intlistMax(SqList sql){ int res = sql.elem[0]; for (int i = 1; i < sql.length; ++i) { if (sql.elem[i] > res) { res = sql.elem[i]; } } return res; }
intlistMin(SqList sql){ int res = sql.elem[0]; for (int i = 1; i < sql.length; ++i) { if (sql.elem[i] < res) { res = sql.elem[i]; } } return res; }
//listDelete删除指定元素 voidlistDelete(SqList &sql, int x){ int k = 0; for (int i = 0; i < sql.length; ++i) { if (sql.elem[i] == x) { k++; } else { sql.elem[i - k] = sql.elem[i]; } } sql.length = sql.length - k; }
intmaxPositiveInt(SqList sql){ int min = listMin(sql); int max = listMax(sql); int i = 1; while (sql.length) { if (i < min) break; if (min == i) i++; //删除sql中的最小元素 print(sql); listDelete(sql, min); //重新确定最小元素 min = listMin(sql); } if (min == max) return max + 1; elsereturn i; }
intfindMin(SqList sql){ int n = sql.length; int mark[n + 2] = {0}; for (int i = 0; i < n; ++i) { if (sql.elem[i] > 0 && sql.elem[i] <= n + 1) mark[sql.elem[i]] = 1; } for (int i = 1; i <= n + 1; ++i) { if (mark[i] == 0) return i; } return-1; }