#include<iostream>
using namespace std;
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*LinkList;
LinkList TailInsert(LinkList &L)
{
L=(LNode*)malloc(sizeof(LNode));
L->next=NULL;
LNode *s,*r=L;
int x;
cin>>x;
while(x!=-1)
{
s=(LNode*)malloc(sizeof(LNode));
s->data=x;
r->next=s;
r=s;
cin>>x;
}
r->next=NULL;
return L;
}
void ListVisit(LinkList L)
{
LNode *p=L->next;
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
//查找第1个值为e的元素
LNode *Search_e(LinkList L,int e)
{
LNode *p=L->next;
while(p!=NULL&&p->data!=e)
{
p=p->next;
}
if(p!=NULL)
return p;
else
return NULL;
}
int main()
{
LinkList L;
TailInsert(L);//尾插法
ListVisit(L);//输出
int e;
cin>>e;
LNode *p=Search_e(L,e);//查找第1个值为e的元素
cout<<p->data<<endl;
return 0;
}