Hello guys! I have an assignment in my data structure class and I want to ask following thing:
I have txt file which is unordered (not sorted) say like this:
My program should read file into linked list and sort it while reading? for example: it should read first line "red apple" and place it in first order, then it has to read second line "blue sky" and place it in right order that is before "red apple" (alphabetically blue is upper then red). Next lines has to be ordered in this way.
I know how to make linked list. But i don't know how to sort it while reading text file
Note: I can easily apply some sorting algorithm after reading all content of file. But the main point of assignment is that I cannot use any sorting techniques(algorithms) here.
I nearly know sequence how to make. But i'm very weak at coding. So please can anyone help to me to code following sequence?
//get item //check it with the head of the list //if it's "before" alphabetically //make it the new head and the head its next value //else //iterate through the list performing the same check as above //insert when appropriate //repeat
Anyone can help me to make it?
Thanks in advance