Thread: Linked List won't print

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    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.

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