链表倒置问题答案--2008年4月份二级C
发布时间:2020-12-13 20:36:26 所属栏目:百科 来源:网络整理
导读:#includestdio.h #includestdlib.h struct node { int data; struct node * next; }*head; struct node * newnode() { return (struct node *)malloc(sizeof(struct node)); } void view() { struct node *p=head; while(p) { printf("%3d",p-data); p=p-nex
#include<stdio.h>
#include<stdlib.h> struct node { int data; struct node * next; }*head; struct node * newnode() { return (struct node *)malloc(sizeof(struct node)); } void view() { struct node *p=head; while(p) { printf("%3d",p->data); p=p->next; } } void relist()/*链表倒置*/ { struct node *p1,*p2,*p3; p1=head; p2=p1->next; p3=p2->next; p1->next =NULL; while(p3) { p2->next =p1; p1=p2; p2=p3; p3=p3->next ; } p2->next =p1;head=p2;} void main() { struct node *p1,*p2; int i; head=newnode(); p1=head; head->data=0; head->next=NULL; for(i=1;i<=10;i++) { p2=newnode(); p2->data=i; p2->next =NULL; p1->next=p2; p1=p2; } view(); printf("n"); relist(); view(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 正则表达式 – Bash:一键退出与grep命令相反的状
- Magento – 使用local.xml从产品视图中删除选项卡
- 机房收费系统——技术总结
- Makefile,“配置”文件和其他编译工具 – 它们如
- ruby-on-rails – rails 3和PDFkit
- ruby-on-rails-3.2 – DBI在ruby 1.8.7和2.1之间
- objective-c – 使用NSArray中的NSString检查字符
- Flash ActionScript编程的原则
- ruby-on-rails – Rails – 给@comments如何获得
- objective-c – IOS 8 SplitViewController iPho
热点阅读