Thread: Adding a node to a linked list

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    7

    Adding a node to a linked list

    I'm having the worst time trying to add a node into a linked list. I can't even get the node in. My instructor said this would work, but I think he must have read it over too quickly. The list is supposed to be in ascending order of Zip codes.

    Code:
    struct SListNode{
       char City[41];
       char State[3];
       char Zip[6];
       double Longitude;
       double Latitude;
       long Population;
       struct SListNode *Next;
       struct SListNode *Prev;
       };
    
    void vAddListNode (struct SListHeader *psList, struct SListNode *psNode)
       {
       struct SListNode *psNext=NULL;
       int comp;
       psList->iNodeCount = psList->iNodeCount+1;
       psNext = psList->psHead;
       comp = strcmp(psNode->Zip, psNext->Zip);
       while (comp > 0)
          {
          psNode->Next = psNext;
          psNode->Prev = psNext->Prev;
          psNode->Next->Prev = psNext;
          psNode->Prev->Next = psNext;
          psNext = psNode->Next;
          printf("City5:  %s", psNext->City);
          printf("City5:  %s", psNode->City);
          comp = strcmp(psNode->Zip, psNext->Zip);
          }
       }
    Last edited by slopeski007; 02-01-2003 at 04:46 PM.

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    I'am just posting here, don't forget to add the code tags, you need to open it and close it [] and [/].

    Without this, your code look bad

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    7
    I've figured this out so don't worry about it.

    Scott

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Debugging my AVL tree program.
    By Nextstopearth in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 01:48 AM
  2. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  3. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  4. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  5. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM