#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;
}
//返回只含有原序号为偶数的B表
LinkList Create_AB(LinkList &A)
{
LinkList B=(LNode*)malloc(sizeof(LNode));
B->next=NULL;
LNode *p=A->next;
A->next=NULL;
LNode *ra=A,*sb;
while(p!=NULL)
{
ra->next=p;
ra=p;
p=p->next;
if(p!=NULL)
{
sb=p->next;
p->next=B->next;
B->next=p;
p=sb;
}
}
ra->next=NULL;
return B;
}
int main()
{
LinkList A;
TailInsert(A);//尾插法
ListVisit(A);//输出
LinkList B=Create_AB(A);//返回只含有原序号为偶数的B表
ListVisit(B);
return 0;
}