顺序表删除最小元素 从顺序表中删除具有最小值的元素(假设唯一),并由函数返回被删除元素的值。 删除后空出的位置由最后一个元素填补, 若顺序表为空则显示错误信息并退出运行。 preset.h12345678910111213141516171819202122232425#ifndef _PRESET_H#define _PRESET_H#include <iostream>using namespace std;#define MAXLENGTH 50typedef struct { int elem[MAXLENGTH]; int length;} SqList;void print(SqList sql) { if (sql.length == 0) { cout << "null" << endl; return; } for (int i = 0; i < sql.length; ++i) { cout << sql.elem[i] << " "; } cout << endl;}#endif 参考代码123456789101112131415161718192021222324252627282930313233343536#include "preset.h"//删除最小的元素bool listDelete(SqList &sql, int &e) { if (sql.length == 0) return false; int index = 0; int min = sql.elem[0]; for (int i = 1; i < sql.length; ++i) { if (sql.elem[i] < min) { min = sql.elem[i]; index = i; } } e = min; sql.elem[index] = sql.elem[sql.length - 1]; sql.length--; return true;}int main() { SqList sql = {{10, 7, 2, 1, 4, 3, 6, 5, 8, 9}, 10}; while(true) { int ret; if (listDelete(sql, ret)) { cout << "The deleted element is: " << ret << endl; cout << "Current SqList: "; print(sql); } else { cout << "Unable to delete elements, because the SqList is empty!" << endl; break; } } return 0;}