标签:双向链表
<img src="http://img.blog.csdn.net/20141011162525042?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvUl9NaXNheWE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />#include<iostream> #include<stdlib.h> using namespace std; typedef int ElemType; typedef struct LNode { ElemType data; struct LNode *next1,*next2; }*LinkList; int main() { int n,m,i,t; cin>>n>>m; LinkList L,p,tail; L=new LNode; L->next1=NULL; tail=L; for(i=0;i<n;i++) { p=new LNode; cin>>p->data; p->next1=NULL; p->next2=NULL; tail->next1=p; p->next2=tail; tail=p; } tail=L->next1; while(m--) { cin>>t; for(i=0;i<n;i++) { if(tail->data==t) { if(tail->next2!=L) cout<<tail->next2->data<<" "; if(tail->next1!=NULL) cout<<tail->next1->data<<endl; else cout<<"\n"; } tail=tail->next1; } tail=L->next1; } return 0; }
标签:双向链表
原文地址:http://blog.csdn.net/r_misaya/article/details/39996035