|
发表于 2020-8-22 14:30:01
|
显示全部楼层
#include"alloc.h"
typedef struct node
{
int data;
struct node *next;
}LinkedList;
LinkedList *L;
LinkedList *create()
{LinkedList *head,*p;
int x;
head=malloc(sizeof(LinkedList));
head->next=NULL;
scanf("%d",&x);
while(x!=999)
{p=malloc(sizeof(LinkedList));
p->data=x;
p->next=head->next;
head->next=p;
scanf("%d",&x);
}
return(head);
}
LinkedList *nizhi(LinkedList *head)
{LinkedList *r,*p=head->next;
head->next=NULL;
while(p!=NULL)
{ r=p->next;
p->next=head->next;
head->next=p;
p=r;
}
return(head);
}
void outdL(LinkedList *L)
{ LinkedList *p;
p=L->next;
printf("\n\n");
while(p!=NULL)
{ printf("%d",p->data);
p=p->next;
};
}
main()
{
L=create();
outdL(L);
L=nizhi(L);
outdL(L);
}
|
|