C语言上机报告(链表顺序表堆栈队列二叉树以及几种常见排序算法).docx

C语言上机报告(链表顺序表堆栈队列二叉树以及几种常见排序算法).docx

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

上机报告上机实验一:顺序表相关操作。程序:#includestdio.htypedefstructlist_type{int data[20];int num;}list;voidinsertl(list *l,inti,int x){int j;for(j=l-num-1;j=i-1;j--){l-data[j+1]=l-data[j];}l-data[i]=x;l-num++;for(j=0;jl-num;j++){printf(%d,l-data[j]);printf(\n);}}voiddelate(list*L,int k){inti;if(k0||kL-num-1)printf(Error!\n);for(i=k+1;iL-num;i++)L-data[i-1]=L-data[i];L-num--;for(i=0;iL-num;i++)printf(%d ,L-data[i]);printf(\n);} voiddelte_negative(list*L){inti,j;int n;for(i=0;iL-num-1;i++){if(L-data[i]0) { n=L-num;j=i;while(i!=n) { L-data[j]=L-data[j+1];j++;n--; }i--; L-num--;}}for(i=0;iL-num;i++)printf(%d ,L-data[i]);printf(\n);}void main(){list a;inti,n,k,c;for(i=0;i20;i++){scanf(%d,a.data[i]);if(a.data[i]==-1){break;}}a.num=i;printf(请输入要插入的位置);scanf(%d,n);printf(请输入要插入的数值);scanf(%d,k);insertl(a,n,k);printf(请输入要删除的位置);scanf(%d,c);delate(a,c);delte_negative(a);}典型测试数据(输入):数据:96 32 -5 -6 52 36 78 65 -1;插入位置:4;插入数:23;删除位置:5;应输出:1:96 32 -5 -6 23 52 36 78 65; 2:96 32 -5 -6 23 36 78 65; 3:96 32 23 36 78 65;上机时遇到的问题:a.num与a-num区别,以及何时用 a.num何时用 a-num。解决方法:问同学。实验输出:1:96 32 -5 -6 23 52 36 78 65; 2:96 32 -5 -6 23 36 78 65; 3:96 32 23 36 78 65;上机实验二:链表的相关操作:程序:#includestdio.h#includestdlib.htypedefstructnode_type{int number;structnode_type *next;}node_type;typedefstructlist_type{node_type *head;node_type *tail;int length;}list_type;voidcreate_list(list_type *p){printf(请创建一个链表:\n);node_type *p1,*p2;p-length=0;p1=(node_type *)malloc(sizeof(node_type));printf(请输入第1个元素:\n);scanf(%d,p1-number);while(p1-number!=0){p-length++;if(p-length==1)p-head=p1;elsep2-next=p1;p-tail=p1;p2=p1;p1=(node_type *)malloc(sizeof(node_type));printf(请输入第%d个元素:\n,p-length+1);scanf(%d,p1-number);}}voidinsert_list(list_type *p,intinsert_location,node_type *insert_node){node_type *p1;p1=p-head;inti;if(insert_location==1){insert_node-next=p1;p-head=insert_node;}elseif(insert_location==p-length+1){p-tail-next=insert_node;p-

文档评论(0)

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

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

1亿VIP精品文档

相关文档