Computer Science Canada Help with sorting array! |
Author: | an_mui [ Thu Jan 06, 2005 12:18 am ] | ||
Post subject: | Help with sorting array! | ||
Hi I am kind of new to programming, and I have to make a program that will keep track of an user's collection. I need help on making a menu that will allow the user to choose what to do next. I know first I have to accept input from user, and then user ifs and else ifs? Any help is appreciated
- Annie EDIT (Martin): Just changed the tags to syntax ones to try out the new system. Carry on. ![]() |
Author: | wtd [ Thu Jan 06, 2005 12:48 am ] |
Post subject: | |
In psuedo-code:
|
Author: | an_mui [ Mon Jan 10, 2005 9:18 pm ] |
Post subject: | |
Thanks, the help is appreciated =) |
Author: | an_mui [ Tue Jan 11, 2005 5:08 pm ] |
Post subject: | |
Sorry but I've encountered any problem. For my program, I have 4 arrays to store four types of data that the user entered. The tutorials provided on this web site only deal with sorting one array. However.. for my colleciton, if I sort one array, then I must sort the other array in the same order.. or else the data won't match up. Sorry if I am not explaining myself clearly.. here's what I meant Sample Input: 1: 1998, eric, tang 2. 2000, chris, boyd 3. 2003, stephanie, mac If i sort according to first name alphabetically, then Chris would become associated with 1998, and tang.. which is not true. How would I make my program so that if i sort last name / first name alphabetically.. the other entries would also move accordingly? Thank you for the help |
Author: | wtd [ Tue Jan 11, 2005 6:09 pm ] | ||
Post subject: | |||
Don't try to sort four arrays in exactly the same way. Simply have one array of objects. You can create a class which holds all of your data. Let's say I have people, and I want to store their names and ages. Now, I can create a Person class. If I implement the Comparable interface, I'll be ably to sort my array using the Arrays.sort method.
|
Author: | an_mui [ Thu Jan 13, 2005 8:09 pm ] |
Post subject: | |
hm.. I've been havnig difficulties sorting string.. can you help me once more? |
Author: | wtd [ Thu Jan 13, 2005 8:26 pm ] | ||
Post subject: | |||
If you're just sorting an array of strings, that's incredibly easy.
|
Author: | Nezura [ Thu Jan 20, 2005 12:48 am ] | ||
Post subject: | |||
wtd wrote: If you're just sorting an array of strings, that's incredibly easy.
With Arrays.sort does it sort the foo array ...but doesn't output it does it?...how will we make it output the new sorted array?...loops? |
Author: | wtd [ Thu Jan 20, 2005 1:45 am ] | ||
Post subject: | |||
Nezura wrote: wtd wrote: If you're just sorting an array of strings, that's incredibly easy.
With Arrays.sort does it sort the foo array ...but doesn't output it does it?...how will we make it output the new sorted array?...loops? It just sorts the array. Output the array the same way you would normally. Yes, with a loop. |