33
struct node* current = head;
if (current == NULL) return;
while(current->next!=NULL)
{
if (current->data == current->next->data)
{
struct node* nextNext = current->next->next;
free(current->next);
current->next = nextNext;
}
else
{
current = current->next;
}
}
}
Python tilida takrorlanuvchi elementlarni hisobga oluvchi bayroq (flag)
qo’shiladi. Bu bayroq takrorlanuvchi elementni o’chirishda o’rnatiladi va
qadamlar to’xtatiladi, aks holda qadamlar davom ettiriladi.
Listing 21. Python tilida takrorlanuvchi elementni o’chirish
def RemoveDuplicates(self):
if (self.first == None):
return
old = curr = self.first
while curr != None:
_del = 0
if curr.next != None:
if curr.value == curr.next.value:
curr.next = curr.next.next