Thread: Sort linked list

  1. #1
    Unregistered
    Guest

    Unhappy Sort linked list

    I would like to sort a linked list in alphabet order.
    I have a text file created by notepad
    name.dat

    Jeff
    Ann
    Marry
    Joe

    How can I read this string from file into array?

    FILE *fPtr
    if (fPtr = fopen("c:\\data\\name.dat","r")) == NULL
    printf(" File does not exist\n ");
    else
    { blah blah blah }

    I also don't know how to check for the end of line.

  2. #2
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    In theory, what you want to do is create the struct with a pointer to the next instance and that data being stored. Then, when you read in the item from the txt file, go through the list checking and comparing to the previous and next list's data. Then, when it is greater than one item but less than another, insert it into that spot on the list.

    Garfield
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-04-2006, 06:39 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. Linked List Merge Sort
    By LostNotFound in forum C++ Programming
    Replies: 2
    Last Post: 02-17-2003, 10:34 PM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM