![]() |
| | #1 |
| Guest
Posts: n/a
| I understand how to declare the arrays and I know I need to use a for statement to sort but I am having trouble with the idea of sorting them. The arrays are: employee ID, wage, hours, weekly pay. How do I sort the employee ID's into descending order and have the corresponding wage, hours, and weekly pay follow the ID number. Any information on this would be helpful to me as I seem to be struggling with this. Thanks |
|
| | #2 |
| Linguistic Engineer... Join Date: Aug 2001 Location: CA
Posts: 2,424
| there are many swapping sequences [comparisons] you can use to sort the elements of your array... what you could do is look up things like the bubble sort or shell sort and implement these swapping sequences [comparisons] to your data arrays in order to sort them... hth
__________________ hasafraggin shizigishin oppashigger... |
| doubleanti is offline | |
| | #3 |
| Guest
Posts: n/a
| I recommend you to take a look at that: http://www.cpp-home.com/tutorial.php?113_1 This is a tutorial about the selection sort... also, a code example of the selection sort, can be found here: http://www.cpp-home.com/code.php?82_1 If you need C++ resources /tutorials, code, utilities and more.../, feel free to visit www.cpp-home.com Ilia Yordanov, www.cpp-home.com loobian@cpp-home.com |
|
| | #4 |
| Registered User Join Date: Aug 2001
Posts: 47
| If you have a "stable" sorting algorithm, then, to use an example, if you sort wage, and then hours, and then dept. number, you'll get output something like this: Code: DEPT # HOURS WAGE 9999999 82 23 9999999 82 19 9999999 70 90 9999999 70 19 9999999 70 12 8273921 100 9 8273921 100 8 8273921 80 20 7000000 129 12 Selection sort is the most common-sense sorting algorithm. Without having read anything about sorting, I decided I'd code a sorting algorithm, and that's what I came up with. Conversely, although bubble sort is very simple to code, it's not the most intuitive algorithm. Also, unless the data is close to being sorted already, bubble sort will be slooooooooow. The second kind of sorting algorithm I came up on my own I later found was like a bucket sort, except my system had no recursion, and each possible number had its own bucket! So it was very fast [O(n)], but took a lot of memory. This is far from being a general purpose sort, though. The best general-purpose sort is quicksort.My favorite site for information about common algorithms and data structures including those used for sorting and searching is http://ciips.ee.uwa.edu.au/~morris/Y...10/ds_ToC.html . |
| TerranFury is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sorting problem with structures and arrays, could I get some guidance? | badtwistofate | C Programming | 26 | 06-11-2009 11:27 AM |
| Sorting Arrays | DaniiChris | C Programming | 11 | 08-03-2008 08:23 PM |
| Parallel arrays, dynamic memory allocation, and sorting arrays | sbaker1313 | C Programming | 16 | 01-01-2008 04:07 PM |
| Sorting Multiple Arrays with complications of 2D arrays and strings. | compiler151 | C Programming | 2 | 02-23-2004 06:34 AM |
| Sorting 2.. 1-D arrays of different types | GaGi | C Programming | 3 | 04-04-2002 05:29 PM |