If you use parallel arrays to input an address for a phone directory program. Such as this
Walter J. Freeman
8752 W. Miles Rd.
Adrian Mi, 48719
Then at a later time in the program you have to display the entire directory sorted by last name. How would you go about doing this? I'm so confused. How do I keep the arrays together and what would be the best way to input this info? At a later time I have also have to be able to modify the first name last name and such. So should the first name go into it's own array the last into its own?
The big thing is how would any information be in order if I have to display the info sorted by last name?
I'm really in a bind with this.
If you use parallel arrays to input an address for a phone directory program... Then at a later time in the program you have to display the entire directory sorted by last name. How would you go about doing this?
If you know how to sort an array, you're pretty much 95% of the way there.
All you need to remember is that when you swap elements in one array, you must also swap the same elements in all of the parallel arrays.
If you're feeling spunky, you could introduce an array of indices and sort that array based on the names those indices refer to in the parallel arrays. The result of that could be used to traverse the parallel arrays in order of the names, without ever having to modify the parallel arrays.
Oh can you please elaborate cire? I have to sort the infor at one point or another. I think that I will use a structure and declare an array of that type. Now with that said can you tell me more about your idea?
So I have a question I don't know the syntax off my head but what if you had a structure with an array declared of that type. Is it possible to sort that array in alphabetical order according to last name if. ( forgive the syntax) You have the array called info of type telephone( your structure type) and then if you did a sort algorithm with info.last name. Would all the other information fall in line behind that and then the rest would appear with that index. OK not to sound stupid but you know how when geese fly in a v there is a lead and all the rest follow. Is that what would happen if I sorted my array info of type telephone by using info.last name. I hope that makes sense.
I hope that question makes sense.
Dude It says parallel arrays I emailed my instructor and he said structures. So I'm going with structures, It will be much easier I believe. That's exactly what I was asking. I believe. So if I used last name in order to sort then everything will stay together and the last names will be sorted alphabetically?