Thread: Help with Linked List

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    12

    Help with Linked List

    I've heard that hiding a pointer type in a typedef is a bad practice, but this was the assignment given to us. Im having a hard time accessing the lists and "copying" the list. How to copy the pFirst to temp and how to access pLink which is inside pFirst, thanks. next is the one for copying the next link.
    Code:
    typedef struct
    {  char strIDNo[9];
       /* any other information for student here */
    }studentType;
    
    struct nodeTag
    {
        studentType sData;
        struct nodeTag *pLink;
    };
    
    typedef struct nodeTag nodeType;
    typedef nodeType * ptrNode;
    
    void sort(ptrNode *pFirst){
         
         ptrNode *temp,*next;
         temp=pFirst;
         next=pFirst->pLink;

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    63
    What do you mean by "copy"? Also, check this logic out:

    ptrNode is a nodeType *.
    What is pFirst then?

    Think about the difference between char* and char**.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    12
    Does this mean i got no way to access the pLink? well since this would be sorting of the linked list, u got other way?

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    63
    Does this mean i got no way to access the pLink?
    There is a way to access pLink.

    My post was basically trying to hint that part of your code doesn't make sense:

    Code:
    void sort(ptrNode *pFirst){
          
         ptrNode *temp,*next;
         temp=pFirst;
         next=pFirst->pLink; /* WRONG */
    Can you figure out why?

    In your code, a ptrNode is a nodeType*. So a ptrNode* is then a nodeType**.

    If pFirst was a nodeType*, then pFirst->pLink would make sense.

    But because pFirst is a nodeType**, you would have to do something like pFirst[0]->pLink.

    Do you have a sorting algorithm in mind?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-01-2010, 10:19 PM
  2. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  3. singly linked list to doubly linked list
    By t48j in forum C Programming
    Replies: 3
    Last Post: 03-23-2005, 06:37 PM
  4. bi-linked list based on one-way linked list
    By ronenk in forum C Programming
    Replies: 1
    Last Post: 03-04-2005, 08:16 AM
  5. Replies: 6
    Last Post: 03-02-2005, 02:45 AM