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

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

上机报告上机实验一:顺序表相关操作。程序:#includetypedefstructlist_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;jnum;j++){printf("%d",l->data[j]);printf("\n");}}voiddelate(list*L,int k){inti;if(k<0||k>L->num-1)printf("Error!\n");for(i=k+1;inum;i++)L->data[i-1]=L->data[i];L->num--;for(i=0;inum;i++)printf("%d ",L->data[i]);printf("\n");} voiddelte_negative(list*L){inti,j;int n;for(i=0;inum-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;inum;i++)printf("%d ",L->data[i]);printf("\n");}void main(){list a;inti,n,k,c;for(i=0;i<20;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;上机实验二:链表的相关操作:程序:#include#includetypedefstructnode_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){inse

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值