初始化顺序表
SeqList() { int Length = 0; }
建立顺序表
SeqList(int a[], int n) { if (n > MaxSize)throw"参数非法"; for (int i = 0; i < n; i++ + ) data[i] = a[i]; length = n; }
判空
Employ() { if (length == 0)return1; else return 0; }
长度
Length() { return length; }
按位查找
Get(int i) { if (i<1 && i>length)throw"查找位置非法"; else return data[i - 1]; }
按值查找
Locate(int x) { for (int i = 0; i < length; i++) { if (data[i] == x)return i + 1; else return 0; } }
Insert(int i,int x) { if (length == MaxSize)return"上溢"; if (i<1 || i>length + 1)throw"插入位置错误"; for (int j = length; j >= i; j--) data[j] = data[j - 1]; data[i - 1] = x; length++; }
遍历
PrintList() { for (int i = 0; i < length; i++) { cout << data[i] << "t"; cout<欢迎分享,转载请注明来源:内存溢出
评论列表(0条)