思维导图
1、顺序表按元素删除
代码:
int delete_num_delete(sqlist *list,datatype key)
{int index=seek_num(list,key);//元素查找函数if(index==-1){return -1;}delete_index(list,index);return 0;
}
2、顺序表按照元素修改
代码:
//顺序表按照元素修改
void exchange(sqlist *list ,int key,int element)
{int index=-1;index=seek_num(list,key);//元素查找函数if(index==-1){printf("没有找到\n");}else{list->data[index]=element;}
}
3、顺序表按照元素查找
代码:
//按照元素查找
int seek_num(sqlist *list,datatype key)
{int index=-1;for(int i=0;i<list->len;i++){if(key==list->data[i]){index=i;}}if(index==-1){return -1;}else{return index;}
}
4、顺序表去重
代码:
//顺序表去重
void delete_duoyu(sqlist *list)
{for(int i=0;i<list->len-1;i++){for(int j=i+1;j<list->len;j++){if(list->data[i]==list->data[j]){delete_index(list,j);//根据下标删除j--;}}}
}
5、顺序表排序
代码:
void bubble(sqlist *list)
{for(int i=1;i<list->len;i++){for(int j=0;j<list->len-i;j++){if(list->data[j]<list->data[j+1]){datatype t=list->data[j+1];list->data[j+1]=list->data[j];list->data[j]=t;}}}puts("排序后效果为:");output(list);
}
6、顺序表释放
代码:
//释放内存
sqlist *free_space(sqlist *list)
{if(NULL==list){return NULL; }free(list);list=NULL;return list;
}