لیست پیوندی دو طرفه رو هم اگه SEARCH کنی راحت پیدا می شه. من خودم یه لیست آماده دارم که به دردت نمی خوره ولی تابع هاشو می ذارم این جا. شاید به دردت بخوره.
struct node{
int number;
node *next,*last;
node(){
next=0;
last=0;
}
};
void add(node *a,int x){
node *temp,*v;
temp=a;
while ((*temp).next!=0){
temp=(*temp).next;
}
v=new node;
(*v).number=x;
(*temp).next=v;
(*v).last=temp;
}
node* search(node *a,int x){
node *temp;
temp=a;
while ((*temp).next!=0){
if((*temp).number==x){
break;
}
temp=(*temp).next;
}
if ((*temp).next==0){
cout<<"not neighbour"<<endl;
}
else
cout<<"are neighbour"<<endl;
return temp;
}
void delet(node *a,int x){
node *temp,*b;
temp=search(a,x);
if ((*temp).next!=0) {
b=temp;
(*((*b).last)).next=(*temp).next;
(*((*b).next)).last=(*temp).last;
cout<<(*b).number<< " DELETED"<<endl;
}
else if((*temp).last==0)
cout<<"EMPTY"<<endl;
else {
(*((*temp).last)).next=0;
(*temp).last=0;
cout<<(*temp).number<< " DELETED"<<endl;
}
}