Linked Lists : removeduplicate(); problem.

This is a discussion on Linked Lists : removeduplicate(); problem. within the C++ Programming forums, part of the General Programming Boards category; Hi,
I'm doing the linked list excercises from http://cslibrary.stanford.edu/105/ . Currently I'm on #10, removeduplcate();. It takes a linked list ...

Linked Lists : removeduplicate(); problem.

Hi,

I'm doing the linked list excercises from http://cslibrary.stanford.edu/105/. Currently I'm on #10, removeduplcate();. It takes a linked list that is sorted and then removes all duplicates. I've written some code and doodled on paper how it should work, however, it keeps going on in an infinte loop, somewhere, and I'm not sure where =P Here's the code. I've ommited the parts that don't have any use.

Code:

struct Node{
int data;
struct Node * next;
};

Code:

void Push(struct Node **Head, int data){
struct Node * NewNode = new Node; // Makes a new node and a pointer 'NewNode' to it
NewNode->data = data;
NewNode->next = *Head; // Sets the next field to point at what headpointer is pointing at
*Head = NewNode; // Copies the pointer of NewNode to HeadPointer
}

void RemoveDuplicate(struct Node * HeadPointer){
if(HeadPointer != NULL){ // Only work if we have something to check for
struct Node * Previous; // Create the pointers
struct Node * Current = HeadPointer;
struct Node * Temp;
Previous = Current; // Previous will point to the "original" node to check against. The
Current = Current->next; // node after it willl be deleted if it's the same as the original
while(Current != NULL){
if( Current->data == Previous->data){ // If two nodes next to each other are the same
Temp = Current; // Set temp to point at the second copy..
Current = Current->next; // Advance current to point to the third node
delete Temp; // delete the copy (middle node)
Previous->next = Current; // Connect the first node to the third node
}
else{ // if two adjoining nodes aren't the same..
Previous = Current; // Advance the previous pointer...
Current = Current->next; // Advance current
}
}
}
}