Thread: i need a bit of help .....

  1. #1
    Registered User
    Join Date
    Mar 2002

    Unhappy i need a bit of help .....

    hi guys !
    the problem i am dealing with is regarding linked lists. phewwwwww! i am stuck with these pointers the thing is that i am unable to make the insEnd() function of the linked lists that inserts a node at the end of the list. Problem is that i lose the pointer to the first node ,so only last info is available. actually i am making lists that can work on few string functions. ill tell thier details later but the main problem is that how do i akeep track of the first pointer. ...? plz if anyone could help me in making that or anyone has done a project or assignment like that help mee!

  2. #2
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Implement :

    node *Head;
    node *Current;
    node *Tail;

    In your Linked List class or main();

    If your inserting nodes on the end, you shouldn't be losing the first node (or any nodes for that matter). If you are (like you said) you're not adding them onto the end of the list properly.

    essentially your Tail->;

    Posting revelent code always helps.

  3. #3
    Registered User
    Join Date
    Mar 2002
    It can be done in any number of ways. Here's one that doesn't use a list class, doesn't use a tail node, and isn't "functionalized", although those are all valid options, and something you should think about.

    struct node
    int data;
    node * next;

    int main()
    node * head = NULL;//the list
    node * current;

    //get a new node
    node * newNode = new Node;

    //initialize the new node:
    newNode->data = 14;
    newNode->next = NULL:

    //insert at end of list
    //first find end of list, starting at head and moving down
    current = head;
    while(current->next != NULL)
    current = current->next;

    //then figure out where you are before doing anything.
    if(current == head) //means list was empty
    head = newNode;
    else //list wasn't empty
    current->next = newNode;


  4. #4
    Registered User
    Join Date
    Mar 2002

    Thumbs up thanks!

    thanks for ur help guys ! i 've been able to sought it now ! i'll probably ask again if i am stuck in upcoming trees assignment ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bit manipulation
    By Neo1 in forum C++ Programming
    Replies: 8
    Last Post: 03-24-2008, 11:53 AM
  2. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 09:20 AM
  3. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 10:54 AM
  4. Bitwise Operators - Setting and Retreiving a Bit
    By Spono in forum C Programming
    Replies: 2
    Last Post: 11-04-2003, 02:09 PM
  5. Bit Manipulation Questions
    By CPPNewbie in forum C++ Programming
    Replies: 7
    Last Post: 08-12-2003, 02:17 PM