Thread: Sorting a Linked List

  1. #1
    Registered User
    Join Date
    Nov 2008

    Sorting a Linked List

    Ok I am trying to sort a linked list and I have declared
          struct SongNode
                 Song s;                  //value in this node
                 SongNode *next;          //cursor points to where the node is 
          SongNode *head;                 //points to the begining
          static const int MAX_MEMORY = 256;       //most memory allowed
    and used
    void BobCatPod::sort( )
         SongNode *i;
         SongNode *i_n;
         SongNode *j;
         SongNode *temp;
         if (head == NULL)
         j = head;
         while (j -> next != NULL)
               j = j-> next;
               while (j!= head)
                     i = i_n =head;
                     while (i_n != j)
                           if (i_n-> next-> s < i_n-> s  )
                                      temp=i_n-> next;
                                      i_n-> next = temp-> next;
                                      temp-> next =i_n;
                                      if (i_n-> next = temp);
                                      next = temp;
                                      i = i_n;
                                      i_n= i_n->next;
    now in this line
                                      next = temp;
    I get an error that says next is undeclared. Why???

  2. #2
    The larch
    Join Date
    May 2006
    Does BobCatPod have a member called next?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  2. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  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