单链表逆序(共3页).docx





《单链表逆序(共3页).docx》由会员分享,可在线阅读,更多相关《单链表逆序(共3页).docx(3页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上head.h头文件头文件内内容:#include#includestruct node *head;struct node *last;linklist.c单链表的建立,插入打印,逆序#includehead.hstruct node int num; struct node *next;void init()/*单链表初始化*/ head = (struct node *)malloc(sizeof(struct node); last = (struct node *)malloc(sizeof(struct node); head-next = NULL; la
2、st = head;void insert(int num)/*插入*/ struct node *new = (struct node *)malloc(sizeof(struct node); new-num = num; new-next = NULL; last-next = new; last = new;void display()/*打印函数*/ struct node *ptr = head-next; while(ptr != NULL) printf(%d ,ptr-num); ptr = ptr-next; printf(n);void reverse()/*主要的逆序部
3、分*/ struct node *ptr = head-next; struct node *str = ptr-next; struct node *new = str; ptr-next = NULL;/*猜猜这句是干嘛的?*/ while(str != NULL) str = str-next; new-next = ptr; ptr = new; new = str; head-next = ptr;void my_insert()/*没用到*/ int i; int num; for(i = 0;i5;i+) printf(please input num:); scanf(%d,&num); insert(num); linklist_reverse.c主函数,起到一个测试的作用,具体函数都在Linklist.cl里#includehead.hint main() int i; int num; init(); /my_insert(); insert(1); insert(2); insert(3); display(); /printf(1111n); reverse(); display(); return 0;专心-专注-专业
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单链表 逆序

限制150内