I'm working on a small phone book program. When a new entry is added to the phone book old entries should reorder themselves in the array alphabetically. For example, if the array contains:
and I'm trying to add Bob, Fred and Jeff should be pushed down. I was thinking of using strncmp() to determine the numerical value of each entry. But I'm not sure where I'd go beyond there.
PS. The same thing should happen when an entry is deleted from the phone book.
Thanks in advance :)
What you would need is a sorted list. I don't know if std::set is such a one? Others can probably tell you more.
Yes, objects stored in a set container are automatically ordered by default according to the less-than operator for whatever type (can be overridden and should be for complex/aggregate types) is stored within the container. Objects inserted into or deleted from the container will preserve that ordering.
First you have a multidimmensional array. An array in an array. An array of words with an array of letters. We get the first letter of all arrays and they arrange themselves alphabetically for we convert all them to numbers (typecasting). They replace each other endlessly until it all goes lowest to greatest. I admit this is very unclear and is easier said than done.