473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how can i sort words in c?

given a linked list of words, how can i sort them out alphabetically in c? pls help me... i'm really having a hard time in this problem..
Mar 13 '07 #1
3 4967
Ganon11
3,652 Expert 2GB
You will have to use strcmp(char* str1, char* str2), which returns 1 if str1 is greater than str2, -1 if str1 is less than str2, and 0 if they are equal. For the actual sorting, there are plenty of algorithms that you can find online, such as the Bubble Sort, the Quicksort, or the Insertion sort algorithms. You will have to implement these algorithms yourself, though.
Mar 13 '07 #2
lqdeffx
39
I would recommend using qsort just because it is already developed and enhanced and will meet most needs. Plus you won't have to create anything crazy or complicated.
Mar 13 '07 #3
Banfa
9,065 Expert Mod 8TB
I would recommend using qsort just because it is already developed and enhanced and will meet most needs. Plus you won't have to create anything crazy or complicated.
Unfortunately qsort works on an array not a linked list.

For linked lists another method is rather than using a sorting algorithm just to recreate the list in the desired order

Expand|Select|Wrap|Line Numbers
  1. PSEUDOCODE
  2. HEAD OF SortedList =HEAD OF UnsortedList
  3. REMOVE HeadOfUnsortedList
  4.  
  5. WHILE UnsortedList NOT EMPTY
  6.    NextEntryToInsert = HEAD OF UnsortedList
  7.    REMOVE HeadOfUnsortedList
  8.  
  9.    SCAN DOWN SORTED LIST FOR POSITION TO INSERT NextEntryToInsert
  10.    INSERT NextEntryToInsert
  11. WEND
  12.  
Mar 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kamilche | last post by:
I've written a generic sort routine that will sort dictionaries, lists, or tuples, either by a specified key or by value. Comments welcome! import types def sort(container, key = None,...
7
by: Voetleuce en fênsievry | last post by:
Hello everyone. I'm not a JavaScript author myself, but I'm looking for a method to remove duplicate words from a piece of text. This text would presumably be pasted into a text box. I have,...
2
by: BjoernJackschina | last post by:
Hello, I just look for a capability to sort several words in view of alphabet. An example: stop is 'opst' reach is 'aechr' This should read in a new file so that I can look for same letter...
0
by: Slowjam | last post by:
How do I correct the program below to search all the anagrams in a given file. First, for each word, build another word (its key) with all its letters sorted. For instance, build "dorw" for...
14
by: william.hooper | last post by:
There is a longer article about this subject here: http://www.codeproject.com/useritems/SortedList_Bug.asp See the main article and the reply thread started by Robert Rohde. Alternatively look...
2
by: teddarr | last post by:
I have this assignment where I am to create 3, 100 position arrays, 1 integer, 1 float, and 1 of quotes. Then I am to use a generic type function template to sort the integers into ascending order,...
6
by: Xernoth | last post by:
Hi, I have an exercise that requests the following: Write a function that reads words from an input stream and stores them in a vector. Use that function both to write programs that count the...
6
by: Jimmy45 | last post by:
Hello, I am writing a "scrabble code" on Python. I have some problem with getting possible words from the given letters. For example: Given letters are: 'c', 'r', 'n', '*' Here '*' can be any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.