#include <stdio.h>
#include <malloc.h>
struct node
{
int inum;
struct node *next;
};
struct node *create()
{
struct node *head,*tail,*p;
head = (struct node*)malloc(sizeof(struct node));
head->next = NULL;
tail = head;
do
{
p = (struct node *)malloc(sizeof(struct node));
p->next = NULL;
scanf("%d",&p->inum);
tail->next = p;
tail = p;
}while(p->inum != (-1));
return (head);
}
void Reverse(struct node *head)
{
struct node *p,*q;
p = head->next;
head->next = NULL;
q = p->next;
while(p != NULL)
{
p->next = head->next;
head->next = p;
p = q;
if(q !=NULL)
q = q->next;
}
}
void print(struct node *head)
{
struct node *p;
p = head->next->next;
while(p != NULL)
{
printf("%d ",p->inum);
p = p->next;
}
}
int main()
{
struct node *Head;
Head = create();
Reverse(Head);
print(Head);
return 0;
}
sdut.acm2012级《程序设计基础Ⅱ)》_链表 数据结构实验之链表三:链表的逆置
最新推荐文章于 2020-06-04 22:52:59 发布