从顺序表中删除最小值的元素(假设唯一)并由函数返回被删元素的值,
空出位置由最后一个元素填补,若顺序表为空,则显示出错信息并退出运行
#include <iostream>
#define ok 1
#define error 0
#define MaxSize 100
using namespace std;
typedef int ElemType;
typedef int status;
//定义
typedef struct
{
ElemType *elem;
int length;
}SqList ;
//初始化
status InitList(SqList &L)
{
L.elem = new ElemType[MaxSize];
if (L.elem == 0)
return error;
else
int length = 0;
return ok;
}
//创建
status CreatList(SqList &L, int n) //创建一个长度为n的顺序表
{
for (int i = 0; i < n ; i++)
cin >> L.elem[i];
L.length = n;
return ok;
}
//删除顺序表中最小值元素,并用e返回其值
/*——————————————————————*
搜索整个顺序表,查找最小值元素,并记住其位置
搜索结束用最后一个元素填补删除元素
*——————————————————————-*/
int DeleteList(SqList &L, ElemType &e)
{
if (L.length == 0) //表空,错误退出
return error;
e = L.elem[0]
顺序表中删除最小值的元素
最新推荐文章于 2024-08-02 17:06:55 发布