Thread: A linkedlist that has no end

  1. #1
    Registered User
    Join Date
    Dec 2002

    A linkedlist that has no end

    i have a project to do and it involves a linked list , and this list is circular. Somebody posted a question on this but it dident help me. I have a delete function and after it deletes a node i must print the remaining list, and thats where my problem is. heres is an example

    The list after deleting 92:
    6685124 82 62 72 99

    The list after deleting 72:
    6685124 82 62 7801996 99

    needs to print

    The list after deleting 92:
    82 62 72 99

    The list after deleting 72:
    82 62 99

    idk what the hell is causing my program to print that out , someone check it out for me, here is some code that i think is the problem

    void ClosedList::Delete(int item)
    	NodeType* delPtr;
        NodeType* currPtr;
        if (item == head->component)
    		delPtr = head;
    		head = head->link;
    	currPtr = head;
            while (currPtr->link->component != item)
    		currPtr = currPtr->link;
    	delPtr = currPtr->link;
            currPtr->link = currPtr->link->link;
        delete delPtr;
    void ClosedList::Print() const
    	NodeType* currPtr = head->backlink;
    	    cout << currPtr->component << "    ";
                currPtr = currPtr->backlink;
            }while (currPtr!= head);               
            cout << currPtr->component << "    ";
    bool ClosedList::IsEmpty() const
    	return (head == NULL);

  2. #2
    Registered User
    Join Date
    Mar 2002
    wassa matter, u don lik garbage, man?

    In my experience when I get unexpected garbage out if I'm using a pointer it means I've got a dangling pointer someplace.

    Looking at your code I see pointers to both link and backlink suggesting this is a doubly linked list, yet in the delete() function you only deal with one of the two links necesarry to create a doubly linked list. Alternatively, you have a singly linked list, but are incorrectly namiing the pointer in one or the of the functions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  2. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM
  5. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 02:40 PM