码迷,mamicode.com
首页 > 其他好文 > 详细

SDUTOJ 2054 双向链表

时间:2014-10-11 17:53:55      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:双向链表

bubuko.com,布布扣
#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;
}
		

SDUTOJ 2054 双向链表

标签:双向链表

原文地址:http://blog.csdn.net/r_misaya/article/details/39996115

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!