欢迎来到天天文库
浏览记录
ID:35559290
大小:44.46 KB
页数:41页
时间:2019-03-28
《软件技术基础实验上机整理》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、一、顺序表://定义#defineMAXNUMxxxtypedefstructlist_type_t{elemtypedata[MAXNUM];intlength;}list_type;list_typetable;//初始化顺序表list_type*init_table(){list_type*table;table=(list_type*)malloc(sizeof(list_type));returntable;}//创建顺序表并输入初始元素内容voidcreat_table(list_type*table){inti,elem;table->length=0;printf(
2、"pleaseinputdatasofthetable");for(i=0;idata[i]=elem;table->length++;}}//将制定元素放入到顺序表的末尾,添加新元素intadd_table(table_t*table,intdata){if(table->length>=MAXNUM)return-1;table->data[table->length]=data;table->length++;return0;}//将指定元素插入到顺序表的指定位
3、置之前intinsert_table(table_t*table,element_tdata,intlocation){intj;location=location-1;if(location<0)return-1;else{if(location>table->length){41location=table->length;table->data[location]=data;}else{for(j=table->length-1;j>=location;j--)table->data[j+1]=table->data[j];table->data[location]=data
4、;table->length++;}return0;}}//将指定元素插入到指定位置voidinsert_table(table_type*table,intlocation,intnew_node){inti;if(table->length>=MAXNUM)printf("Thetableisfall.");if(location<1
5、
6、location>table->length+1)printf("Locationerror.");for(i=table->length-1;i>=location-1;i--)table->data[i+1]=table->data
7、[i];table->data[i+1]=new_node;table->length++;}//将指定位置元素删除voiddelete_table(table_type*table,intlocation){inti;if(table->length<1)Printf(it’sempty!);else{if(location<1
8、
9、location>table->length)printf("Locationerror.");else{for(i=location;i<=table->length;i++)table->data[i-1]=table->data[i];tab
10、le->length--;}}}//将顺序表的内容输出到屏幕上voidshow_table(table_type*table){inti;printf("These%drecordsare:",table->length);if(table->length<=0)printf("It'sempty!");for(i=0;ilength;i++)printf("%4d",table->data[i]);printf("Thelengthofthetableis%d",table->length);41}//实现顺序表在原表上反序voidchange_tab
11、le(list_type*table){inti;inttemp;for(i=0;ilength/2;i++){temp=table->data[i];table->data[i]=table->data[table->length-1-i];table->data[table->length-1-i]=temp;}}//将指定元素按照从小到大顺序插入到顺序表中voidinsert_table_by_order(table_t*table,intdat
此文档下载收益归作者所有