为了账号安全,请及时绑定邮箱和手机立即绑定

创建链表,然后原地逆转,最后编历,不知道哪里错了

创建链表,然后原地逆转,最后编历,不知道哪里错了

小画冰 2016-04-07 21:22:23
#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;}
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1607 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信