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
Code:
void ClosedList::Delete(int item)
{
NodeType* delPtr;
NodeType* currPtr;
if (item == head->component)
{
delPtr = head;
head = head->link;
}
else
{
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;
if(!IsEmpty())
{
do
{
cout << currPtr->component << " ";
currPtr = currPtr->backlink;
}while (currPtr!= head);
cout << currPtr->component << " ";
bool ClosedList::IsEmpty() const
{
return (head == NULL);
}