欢迎来到天天文库
浏览记录
ID:38592014
大小:100.50 KB
页数:9页
时间:2019-06-15
《链表,遍历,冒泡,顺序表,二叉树,叶子节点,递归》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一、单向冒泡#include#defineN5voidmain(){inta[N];inti,j,temp;printf("输入待排序数据:");for(i=0;ia[j+1]){temp=a[j];a[j]=a[j+1];a[j+1]=temp;}printf("排序后的数据为:");for(i=0;i2、ude#include#defineLIST_INIT_SIZE100#defineLISTINCREMENT10#defineERROR0typedefstruct{int*elem;intlength;intlistsize;}SqList;intInitList_Sq(SqList&L){L.elem=(int*)malloc(LIST_INIT_SIZE*sizeof(int));//if(!L.elem)printf("ERROR");L.length=0;L.listsize=LIST_INIT_SIZE;retu3、rn1;}//有序插入(元素值递增有序,在顺序表第i个位置之前插入e)intListInsert_Sq(SqList&L,inte){inti=L.length-1;while(i>=0&&e=i+1;j--)L.elem[j+1]=L.elem[j];L.elem[i+1]=e;L.length++;return1;}//ListInsert_SqintListDelete_Sq(SqList&L,inti,int&e){//删除第i个元素,用e返回i4、nt*p;int*q;//if((i<1)5、6、(i>L.length))returnERROR;p=&(L.elem[i-1]);e=*p;q=L.elem+L.length-1;for(++p;p<=q;++p)*(p-1)=*p;--L.length;printf("删除的值为:%d",e);return1;}//ListDelete_Sq//遍历voidscan_Sq(SqList&L){inti;for(i=0;i7、SqListLa,SqListLb){inti;for(i=0;i8、printf("theListis:");scan_Sq(L);//--------------==================printf("插入何数");scanf("%d",&e);//why%d后去掉才能正常执行ListInsert_Sq(L,e);printf("插入后的顺序表为:");scan_Sq(L);//…………………………………………………插入printf("wheretodeletewhat?");scanf("%d",&i);ListDelete_Sq(L,i,e);printf("删除后的顺序表为:");sca9、n_Sq(L);//……………………………删除InitList_Sq(La);InitList_Sq(Lb);printf("请输入表La元素个数:");scanf("%d",&La.length);printf("请输入元素值:");for(i=0;i10、]);}M
2、ude#include#defineLIST_INIT_SIZE100#defineLISTINCREMENT10#defineERROR0typedefstruct{int*elem;intlength;intlistsize;}SqList;intInitList_Sq(SqList&L){L.elem=(int*)malloc(LIST_INIT_SIZE*sizeof(int));//if(!L.elem)printf("ERROR");L.length=0;L.listsize=LIST_INIT_SIZE;retu
3、rn1;}//有序插入(元素值递增有序,在顺序表第i个位置之前插入e)intListInsert_Sq(SqList&L,inte){inti=L.length-1;while(i>=0&&e=i+1;j--)L.elem[j+1]=L.elem[j];L.elem[i+1]=e;L.length++;return1;}//ListInsert_SqintListDelete_Sq(SqList&L,inti,int&e){//删除第i个元素,用e返回i
4、nt*p;int*q;//if((i<1)
5、
6、(i>L.length))returnERROR;p=&(L.elem[i-1]);e=*p;q=L.elem+L.length-1;for(++p;p<=q;++p)*(p-1)=*p;--L.length;printf("删除的值为:%d",e);return1;}//ListDelete_Sq//遍历voidscan_Sq(SqList&L){inti;for(i=0;i7、SqListLa,SqListLb){inti;for(i=0;i8、printf("theListis:");scan_Sq(L);//--------------==================printf("插入何数");scanf("%d",&e);//why%d后去掉才能正常执行ListInsert_Sq(L,e);printf("插入后的顺序表为:");scan_Sq(L);//…………………………………………………插入printf("wheretodeletewhat?");scanf("%d",&i);ListDelete_Sq(L,i,e);printf("删除后的顺序表为:");sca9、n_Sq(L);//……………………………删除InitList_Sq(La);InitList_Sq(Lb);printf("请输入表La元素个数:");scanf("%d",&La.length);printf("请输入元素值:");for(i=0;i10、]);}M
7、SqListLa,SqListLb){inti;for(i=0;i8、printf("theListis:");scan_Sq(L);//--------------==================printf("插入何数");scanf("%d",&e);//why%d后去掉才能正常执行ListInsert_Sq(L,e);printf("插入后的顺序表为:");scan_Sq(L);//…………………………………………………插入printf("wheretodeletewhat?");scanf("%d",&i);ListDelete_Sq(L,i,e);printf("删除后的顺序表为:");sca9、n_Sq(L);//……………………………删除InitList_Sq(La);InitList_Sq(Lb);printf("请输入表La元素个数:");scanf("%d",&La.length);printf("请输入元素值:");for(i=0;i10、]);}M
8、printf("theListis:");scan_Sq(L);//--------------==================printf("插入何数");scanf("%d",&e);//why%d后去掉才能正常执行ListInsert_Sq(L,e);printf("插入后的顺序表为:");scan_Sq(L);//…………………………………………………插入printf("wheretodeletewhat?");scanf("%d",&i);ListDelete_Sq(L,i,e);printf("删除后的顺序表为:");sca
9、n_Sq(L);//……………………………删除InitList_Sq(La);InitList_Sq(Lb);printf("请输入表La元素个数:");scanf("%d",&La.length);printf("请输入元素值:");for(i=0;i10、]);}M
10、]);}M
此文档下载收益归作者所有