#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
typedef struct Node
{
int data;
struct Node *pnext;
}Node,*pNode;
pNode createlist()
{
int len = 5, i = 0;
pNode head,q;
head = (pNode)malloc(sizeof(Node));
q = head;
head->pnext=NULL;
for(i = 0; i < len; i++)
{
pNode p;
p = (pNode)malloc(sizeof(Node));
p->pnext=NULL;
if(p != NULL)
{
printf("succeed\n");
printf("请输入第%d个节点的数据", i+1);
scanf("%d",&p->data);
q->pnext=p;
// p->pnext = NULL;
q=p;
}
else
{
printf("fail\n");
exit(-1);
}
}
return head;
}
pNode change(pNode head)
{
pNode p, q, r;
p = head;
q = NULL;
while(p)
{
r = p->pnext;
p->pnext = q;
q = p;
p = r;
}
return r;
}
void travers(pNode head)
{
pNode p=head->pnext;
while(p != NULL)
{
printf("%d",p->data);
p = p->pnext;
}
return;
}
int main()
{
pNode head;
head = createlist();
head = change(head);
travers(head);
return 0;
}
相关分类