#include
#include
typedef struct
{
int data;
struct node *next;
}node;
void create(node *
#include
#include
typedef struct
{
int data;
struct node *next;
}node;
void create(node *a)
{
a = (node *)malloc(sizeof(node));
node *s, *r=a;
int i, cycle=1;
while(cycle)
{
scanf("%d",&i);
if(i != 0)
{
s = (node *)malloc(sizeof(node));
s->data = i;
s->next = NULL;
r->next = s;
r = s;
}
else
cycle = 0;
}
r = a;
a = a->next;
free(r);
}
void disa(node *a, node *b)
{
b = (node*)malloc(sizeof(node));
node *p, *r=b;
while(a!=NULL && a->next!=NULL)
{
p=a->next; /*q指向偶数序号的结点*/
a->next=p->next; /*将q从原A中删除*/
r->next=p; /*将q结点链接到B链表的末尾*/
r=p; /*r总是指向B链表的最后一个结点*/
a=a->next; /*a指向原链表A中的大多数序号的结点*/
}
r->next=NULL;/*将生成的B链表中的最后一个结点的link域置空*/
r=b;
b=b->next;
free(r);
}
void print(node *a)
{
for( ; a!=NULL; a=a->next)
{
printf("%d ",a->data);
}
}
int main()
{
node *a, *b;
create(a);
disa(a, b);
print(a);
print(b);
return 0;
}
展开
全部