Witam serdecznie. Podczas pisania programu, stanąłem w jednym miejscu i nie mogę ruszyć.
Chodzi o usuniecie elementu, i wszystkich elementów z listy dwukierunkowej cyklicznej.
Mógłby ktoś udzielić wskazówek, naprostować? Będę wdzięczny!
Usuwanie elementu :
void rm(struct el* &head, struct el* &tail, int a)
{
struct el* temp;
if(head==NULL)
cout<< " \n Sorry, the list is empty.\n";
else if(head->key==a)
{
temp=head;
((head->prev)->next)=head->next;
((head->next)->prev)=head->prev;
head=head->next;
delete temp;
}
else if(tail->key==a)
{
temp=tail;
((tail->prev)->next)=tail->next;
((tail->next)->prev)=tail->prev;
tail=tail->prev;
delete temp;
}
temp=head;
while(temp!=head && temp->key!=a)
temp=temp->next;
if(temp->key==a)
{
((temp->prev)->next)=temp->next;
((temp->next)->prev)=temp->prev;
delete temp;
}
};
Usuwanie wszystkich elementow :
void rmAll(struct el* &head)
{
struct el* temp;
temp=head->next;
while(temp!=head)
{
((temp->prev)->next)=temp->next;
((temp->next)->prev)=temp->prev;
delete temp;
temp=head->next;
}
delete head;
};