sorting two dimensional array in borland bcc 5.5
help!!!
i am creating a basic program in c++. i have an array[20][6]. array[x][0] is for the year, array[x][1] is for the month, array[x][2] is for the date, array[x][3] is for the hour, array[x][4] is for the min and array[x][5] is for the sec. there is a maximum of 20 set of this. i want to sort this array such that the earliest time and date will be found in array[0] and the second earliest in array[1] and so on..i tried doing this using bubble sort and shell sort but it only produces erroneous data.
[512 byte] By [
cipher16] at [2007-11-11 10:22:27]

# 1 Re: sorting two dimensional array in borland bcc 5.5
How are all the time components (hours, second etc.) represented? If they are all integers you can simply flatten the two dimensioanl array into a big one dimensional array and sort it with bubble sort.
Danny at 2007-11-11 20:58:58 >

# 2 Re: sorting two dimensional array in borland bcc 5.5
not sure why integers are special here danny... ?
anyway
loop over all of them, find the smallest, and insert that index into an array of index[20]. Change that piece of data to the maximum value allowed (use a copy of the data, of course!). Repeat 20 times. Loop over the index array, and print the original data pointed to by the index... this is O(N^2) (basically a simple bubble sort for the data arrangement you have) way to sort this type of structure at the expense of a copy operation (with any luck, you can memcyp it all over)...
jonnin at 2007-11-11 20:59:58 >

# 3 Re: sorting two dimensional array in borland bcc 5.5
as opposed to char *, which requires lexicographical comparisons.
Danny at 2007-11-11 21:01:03 >
