C/alphabetical order
Expert: Joydeep Bhattacharya - 3/5/2007
QuestionHi,
I'd like to know what strategy is best to order words in alphabetical order using C. More specifically:
1) Should I make a loop that looks at all letters from the string?
2) Is it better to assign a numeric value to every word based on alphabet and then sort numerically?
3) I have lots of words to sort (tens of thousands thousands). Is it better to first write them all into a file and then read from that file, or would you immediately make a string and sort them directly?
Thanks a lot.
Andres
AnswerHi Andres
While sorting 10000 words one major factor becomes the memory if you have enough memory to store all the word into a character array then it would be much more easier to sort the array just like a dictionary and then throwing the contents of the array to a desired file.
In case if the memory is inadequate or insufficient then i would suggest you to first read all the words from the file starting with A into a character array and then sort the array and throw it in a separate file then look for words starting with b,c,d.....,x,y,z and so on and you get all the words stored sorted in a separate file.
If you face any problem regarding the coding part then please feel free to get back to me.
regards
Joydeep Bhattacharya