Thread: linked list

  1. #1
    Registered User
    Join Date
    Jan 2002

    linked list

    Please can you help with my lniked list I've got a node declared and passed to function
    append_nodes wihtin main, Then in that function I input the elements for the node and assign the
    next pointer to a new node and test for memory.

    I'm not sure where to put my while loop to build new nodes and to include there input and test for memory
    I know where it is now is not possible I've only included it to show what I think I need in my loop.


    int main()
    node *top=new node;



    void append_nodes(struct node *append)

    cout<<"Enter persons name >";

    cout<<'\n'<<"Enter persons age >";

    append->next=new node;




    thanks for the help.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    It's / NOT \ in the tags!

    First step is separate the 'data input' from the 'append list' function.

    Your code in main() should look like
    node = create_node();
    fill_in_data(node);  // this reads from the user
    list = append_list( list, node );  // appends node to list, and returns a (modified) list
    Hopefully, you'll end up with 3 small functions which you can test separately, rather than some 'big bang' function which does everything.

    Note, the list is only really modified when appending a node to an empty list.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM