网站大量收购独家精品文档,联系QQ:2885784924

软件技术基础_链表_上机报告.pdf

  1. 1、本文档共15页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
软件技术基础_链表_上机报告

1 电子科技大学软件技术基础上机实验报告(完整版) 实验二-链表 姓名:小明 学号:2010012039999 ex2_1: 一、 程序流程说明 1)首先创建一个单链表:从键盘读入五个整数,按输入顺序形成单链表。将创 建好的链表元素依次输出到屏幕上。 2)在已创建好的链表中插入一个元素:从键盘读入元素值和插入位置,调用插 入函数完成插入操作。然后将链表元素依次输出到屏幕上。 3)在已创建好的链表中删除一个元素:从键盘读入欲删除的元素位置(序号), 调用删除函数完成删除操作。然后将链表元素依次输出到屏幕上。 二、程序代码 #includestdio.h #includestdlib.h //链点的定义 typedef struct node_type { int data; struct node_type *next; } node_type; //链表的定义 typedef struct list_type { node_type *head; node_type *tail; int length; } list_type; //生成含有5 个链点的单链表 void creatlist(list_type *list ) { list-head = (node_type *)malloc(sizeof(node_type)); int t=5; int x; list-tail=list-head; while(t--) 2 { scanf(%d,x); list-tail-data = x; list-tail-next=(node_type *)malloc(sizeof(node_type)); list-tail =list-tail-next ; } list-length=5; } //遍历元素并依次输出函数 void showlist(list_type *lp) { int i=0; node_type *p; p=lp-head; if(lp-length=0) { printf(No data!\n); return; } while(ilp-length) { printf(%d ,p-data); p=p-next; i++; } } // 插入函数 void insertlist(list_type *list,int new_node ,int location) { node_type *p,*s; p=list-head; if(location == 1) { p-next = list-head; list-head = p; list-head-data=new_node; list-length++; } else { s=list-head; 3 p=(node_type *)malloc(sizeof(node_type)); p-data=new_node; location-=1; while(location--) s=s-next;

文档评论(0)

dajuhyy + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档