Thread: How to sort a link list alphabetically? ( C Programming thru Linux gcc)

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    1

    How to sort a link list alphabetically? ( C Programming thru Linux gcc)

    Generally, my link list will store a list of files and sub directories' name in a folder.

    But now I'm having problem of sorting them alphabetically since I only learned how to sort a link list based on Integer ( ex. code / ID ).

    I was thinking can I generate a number based on the file or sub directory name. Of cause this number should produced by every alphabets in the string and length of string as well. So I can sort them perfectly later. But i was non-stop thinking for almost a day I still cannot figure out how to generate the number sensitively based on every alphabets and length of the string.

    Anyone can advice ? or is there any other better way instead of this one?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I don't understand the purpose of storing the file names and directories. Isn't that the job of the Operating System?

    When I have needed to work with large directories and files, I used a simple script to generate the entire directory of the disk or directory, and used a pipe to put it into a text file.

    Linux should be able to sort the directories and filenames, for you, at the time it generates the list. So your work is done.

    If you REALLY want to do this sorting manually, with a linked list, then I'd suggest sorting the filenames as strings, using strcmp() to do the comparison. Sounds like a lot more work, however.

    AND >> Welcome to the forum!

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why do you need a number? Are you aware of strcmp?


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sort linked list by pointer manipulation
    By budala in forum C Programming
    Replies: 9
    Last Post: 04-24-2010, 03:07 PM
  2. Buidl Library with ./configure script
    By Jardon in forum C Programming
    Replies: 6
    Last Post: 07-24-2009, 09:36 AM
  3. Linked List, Please Help!
    By CodeMonkeyZ in forum C Programming
    Replies: 5
    Last Post: 02-17-2009, 06:23 AM
  4. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  5. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM