You are here:

C/alphabetical order

Advertisement


Question
Hi,
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

Answer
Hi 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

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

Ability to solve C and Data Structure problems and puzzles with simple and easy to understand logic.

Experience

C, C++, Java, Data Structure, PHP, Web Designing

Organizations
http://www.scodz.com Designation: webmaster

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Past/Present Clients
http://analysingc.50webs.com http://www.funforu.com

©2012 About.com, a part of The New York Times Company. All rights reserved.