#include <iostream>
struct ListNode
{
int val;
ListNode *next;
ListNode(int x = 0) : val(x), next(NULL) {}
};
ListNode * RemoveDuplicated(ListNode *head)
{
if (head == NULL) return head;
ListNode * last = head;
ListNode * p = head;
int val = p->val;
while((p = p->next) != NULL)
if (val != p->val)
{
last->next = p;
val = p->val;
last = p;
}
last->next = NULL;
return head;
}
using namespace std;
void PrintList(ListNode* h)
{
while(h)
{
cout << h->val << ',';
h = h->next;
}
cout << endl;
}
int main(int argc, char** argv)
{
int A[] = {1,1,1,1,1,1,2,2,3,3,3,3,3,3,4,5,6,7,8,8,8,9,9,10,10};
int n =sizeof(A)/sizeof(int);
ListNode L[n];
for (int i = 0; i < n-1; ++i)
{
L[i].val = A[i];
L[i].next = L+(i+1);
}
L[n-1].val = A[n-1];
PrintList(L);
PrintList(RemoveDuplicated(L));
return 0;
}