Hi,
I'm doing a fairly basic Java course, and I have to design a very simple phone book programme which will take a small number of phone entries (the number can be predefined so I can use arrays instead of lists), sort them and allow them to be searched.
I'm just concentrating on the sorting part of the problem at the moment, and I'm not sure where to start! There's two ways I can approach it:
1) Create an array of objects, each object containing a variable for a Name and a Phone Number, and then use quicksort on the array to sort the objects. The problems with this (for me anyway, I'm sure this is really easy for you guys!) is that I'm not sure on (a) how to get the individual objects into the array in the first place and (b) how to use quicksort in this case so that the Name variable is used for sorting purposes.
2) Create a much simpler string array containing the names as Strings, and have a second array with the relevant Phone numbers in the corresponding index position. The problems with this approach is that while performing quicksort on the String array to move the names around, I don't know how to ensure that the corresponding telephone number in the second array also moves.
Any help or suggestions much appreciated!
Shane
I'm doing a fairly basic Java course, and I have to design a very simple phone book programme which will take a small number of phone entries (the number can be predefined so I can use arrays instead of lists), sort them and allow them to be searched.
I'm just concentrating on the sorting part of the problem at the moment, and I'm not sure where to start! There's two ways I can approach it:
1) Create an array of objects, each object containing a variable for a Name and a Phone Number, and then use quicksort on the array to sort the objects. The problems with this (for me anyway, I'm sure this is really easy for you guys!) is that I'm not sure on (a) how to get the individual objects into the array in the first place and (b) how to use quicksort in this case so that the Name variable is used for sorting purposes.
2) Create a much simpler string array containing the names as Strings, and have a second array with the relevant Phone numbers in the corresponding index position. The problems with this approach is that while performing quicksort on the String array to move the names around, I don't know how to ensure that the corresponding telephone number in the second array also moves.
Any help or suggestions much appreciated!
Shane
Comment