GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Dec-2003, 12:45
mike3340 mike3340 is offline
New Member
 
Join Date: Oct 2003
Posts: 6
mike3340 is an unknown quantity at this point

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  
Old 15-Dec-2003, 12:57
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
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:
Originally Posted by mike3340
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!
  #3  
Old 15-Dec-2003, 13:22
mike3340 mike3340 is offline
New Member
 
Join Date: Oct 2003
Posts: 6
mike3340 is an unknown quantity at this point
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  
Old 15-Dec-2003, 13:34
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
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  
Old 15-Dec-2003, 13:35
mike3340 mike3340 is offline
New Member
 
Join Date: Oct 2003
Posts: 6
mike3340 is an unknown quantity at this point
thanks a lot for the help! i think i got it from here
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

All times are GMT -6. The time now is 05:15.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.