1.顺序变按元素删除
void del_ele(sqlist *list,int key)
{if(list==NULL||empet_full(list))return;for(int i=0;i<list->len;i++){if(key==list->date[i])del_index(list,i);}
}
int key;printf("please input key:");scanf("%d",&key);del_ele(list,key);output(list);
2.顺序表按元素修改
void find_ele(sqlist* list,int key,int element)
{if(NULL==list||empet_full(list)) return;int index=search_date(list,key);list->date[index]=element;
}
int key;int element1;printf("please input key:");scanf("%d",&key);printf("please input element:");scanf("%d",&element1);find_ele(list,key,element1);output(list);
3.顺序表排序
void sort(sqlist *list,int flag)
{if(flag==1){for(int i=0;i<list->len-1;i++){for(int j=0;j<list->len-i-1;j++){if(list->date[j] > list->date[j+1]){list->date[j] ^= list->date[j+1];list->date[j+1] ^= list->date[j];list->date[j] ^= list->date[j+1];}}}}if(flag==0){for(int i=0;i<list->len-1;i++){for(int j=0;j<list->len-i-1;j++){if(list->date[j] < list->date[j+1]){list->date[j] ^= list->date[j+1];list->date[j+1] ^= list->date[j];list->date[j] ^= list->date[j+1];}}}}
}
int flag;printf("please input flag 1/0");scanf("%d",&flag);sort(list,flag);output(list);
4.顺序表释放空间
sqlist* free_space(sqlist *list)
{if(NULL==list)return list;free(list);list=NULL;return list;
}
5.顺序表有序合并
void combine_date(sqlist* la,sqlist* lb,sqlist* lc)
{int p=0;int q=0;int r=0;//la和lb都有元素while(p<la->len&&q<lb->len){if(la->date[p]<=lb->date[q]){lc->date[r]=la->date[p];p++;r++;lc->len++;}else{lc->date[r]=lb->date[q];q++;r++;lc->len++;}}//la没有元素,lb有元素while(q<lb->len){lc->date[r]=lb->date[q];r++;q++;lc->len++;}//ba没有元素,la有元素while(p<la->len){lc->date[r]=la->date[p];r++;p++;lc->len++;}
}
sqlist *la=creat_space();sqlist *lb=creat_space();sqlist *lc=creat_space();int n;printf("please inout num");scanf("%d",&n);date_type element;//输入for(int i=0;i<n;i++){printf("please input %d element:",i+1);scanf("%d",&element);int flag=inseet_rear(la,element);if(flag==-1){printf("list full or error\n");break;}}sort(la,1);int m;printf("please inout num");scanf("%d",&m);//date_type element;//输入for(int i=0;i<m;i++){printf("please input %d element:",i+1);scanf("%d",&element);int flag=inseet_rear(lb,element);if(flag==-1){printf("list full or error\n");break;}}sort(lb,1);output(la);output(lb);//合并combine_date(la,lb,lc);output(lc);