![]() |
|
#1
|
|||
|
|||
Sorting a 2D array c++i have a 2D array called temps[31][12] that holds temperatures for each day of the year. i need to sort this array in order to find the max and min temps for the year, as well as mode, median, and mean. can anybody get me started on how to sort a 2D array in C++? it doesn't matter if i used selection, bubble, or insertion.
thanks in advance! |
|
#2
|
|||
|
|||
|
I don't see why you've to sort it, if all you want is the mean. Simply add every cell of the array, and divide by (31*12). But I'd think it silly to try and sort a 2D array to find median & mode. It would mess up all the data anyway, since I'm guessing each row stands for days of month, and column for months of year - you'd loose the correspondance.
If you copy each value from the 2D array into a 1D array, and run your fav sort on that, then you'd be able to work out what you want easily enough. Hope this helps GF Quote:
|
|
#3
|
|||
|
|||
|
thanks, that helped. another question:
you were right, the month names are the column headings and the days are the rows. how would i calculate the min, max, mode, median, mean, for just one month. say, just the 2nd column in the array? |
|
#4
|
|||
|
|||
|
It also would be best to copy that data from that month into a 31slot array, and sort & manipulate it from there. If you start swapping data around in your 31*12 array, you've lost the original data & your results are meaningless.
Do you want me to explain how to get max/min & stuff. It's relatively straightforward, especially after sorting this 31 slot array. GF |
|
#5
|
|||
|
|||
|
thanks a lot for the help! i think i got it from here
|
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Extra null element in an array | samtediou | MySQL / PHP Forum | 2 | 11-Dec-2003 11:52 |
| Sorting A Function | misunderstood | MySQL / PHP Forum | 1 | 02-Oct-2003 08:44 |
| deleting from an array | ionyka | C++ Forum | 1 | 02-Sep-2003 03:09 |
| Problem with array | norok | MySQL / PHP Forum | 3 | 16-Jul-2003 02:08 |
| Array_search on a multidimensional array | JdS | MySQL / PHP Forum | 3 | 11-May-2003 06:22 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The