Thread: Linked List won't print

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User ch4's Avatar
    Join Date
    Jan 2007
    Posts
    154
    The very fisrt step before add a node is to initialize the head/last pointers to NULL propably into main.
    Decide the way new items should be inserted to list. (Let's say at the end)
    In the beggining (empty list) head and last are pointing to the same node (aka NULL)
    Adding an item:
    1. Store the new value to an int
    2. Allocate memory (malloc) of the new node to temp pointer. Initialize it. (temp->next = NULL, value = 0 etc)
    3a. if this is the first time adding item then, both head/last pointers should point to temp and next pointer of temp to NULL
    3b. else, next pointer of last node should point to temp and next of temp should point to NULL.
    4. Copy the new value and return new node

    The fifth rule : A real programmer doesn't eat until debugging ends.

    Attachment 12139
    Last edited by ch4; 10-31-2012 at 01:07 PM.

  2. #2
    Registered User
    Join Date
    Oct 2012
    Posts
    4
    Just got back from lunch here is Lab8.h...while I read all the replies.

    Code:
    struct node
    {
        int value;
        struct node *next;
    };
    
    
    struct node *add();
    void print(struct node *list);
    void _delete(int v);
    struct node *find(int v);
    void menu();

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by jrclark View Post
    Just got back from lunch here is Lab8.h...while I read all the replies.
    In my opinion i would say that it is better to post all your replies in one post.
    For example, when you read the answers you are going to post again.So why not enclose the information in one package and enclose it in two?

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    4
    Quote Originally Posted by std10093 View Post
    In my opinion i would say that it is better to post all your replies in one post.
    For example, when you read the answers you are going to post again.So why not enclose the information in one package and enclose it in two?
    Good thing everyone is entitled to there own opinion.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List - Print Backwards
    By skier21 in forum C Programming
    Replies: 9
    Last Post: 07-27-2012, 06:11 PM
  2. Print function in linked list
    By alphasil in forum C Programming
    Replies: 4
    Last Post: 07-08-2012, 08:52 AM
  3. print linked list problem
    By giannis1990 in forum C Programming
    Replies: 8
    Last Post: 05-29-2012, 11:14 AM
  4. i want to print my linked list in the reverse order please help
    By raghu_equinox in forum C Programming
    Replies: 9
    Last Post: 10-14-2006, 12:45 AM
  5. Linked List print out
    By axon in forum C++ Programming
    Replies: 6
    Last Post: 10-19-2003, 07:15 PM