-
I've been stuck.
I want to make a small programme where I input some strings (let's say the names of football teams) and want those strings to get in alphabetical order. I want to input as many strings as I want at the time. Some times I want to put 10, some other time 5 and a third time 23 strings. Don't want to insert them in an arrey, because I don't know how many I will want to put at the time. What should I do? Is list one of the ways to solve it? Is it easy if the part of the programme makes the order A-Z to reverse it to Z-A?
-
Personally, I would go with char **teams and make use of realloc to extend the array when you've reached some limit on the number of teams added.
-
You say if I use an arrey and if that is filled I use the char **teams ?
-
Three options I can see straight off:
1. Memory is cheap. Why not just set an upper teams of 1000 teams, and 100 character long names. Thats < 0.1 megabyte.
2. Put them into a linked list, using malloc() to dynamically allocate storage.
3. Put the into a database.
-
Can you tell me in a few words how to do it with a linked list? What list is the better option on that?
-
Have a look at this tutorial. It uses an int for the data but you could modify to use strings.
Given a linked list which is sorted, how will you insert in sorted way - GeeksforGeeks
-