OJ实验题454线性表的顺序存储结构与操作

为什么总是提示PRESENTATION_ERROR 格式错误

img

#include<iostream>
using namespace std;
class List{
    public:
        List();
        ~List(){}
        void Insert(int i,int x);
        void Get(int i);
        void Find(int x);
        void Delete(int i);
        void PrintList();
    private:
        int data[20]; 
        int len;
}; 
List::List(){
    len = 0; 
} 
void List::Insert(int i, int x){
    if(len >= 20){
        cout << "上溢" <<endl;
    }
    if(i < 1 || i > len+1){
        cout << "位置不正确" << endl;
    }
    for(int j = len; j >= i; j--){
        data[j] = data[j-1];
    }
    data[i-1] = x;
    len++;
}
void List::Get(int i){
    if(i < 1 && i > len){
        cout << "位置不正确" << endl; 
    }
    else{
        cout << data[i-1] << endl;
    }
}
void List::Find(int x){
    int count = 0;
    for(int i = 0; i < len; i++){
        if(data[i] == x){
            cout << i+1 << endl;
            count = 1;
        }
    }
    if(count == 0){
        cout << "None" << endl;
    }
}
void List::Delete(int i){
    int x;
    int j;
    if(len == 0){
        cout << "下溢" << endl; 
    }
    if(i < 1 || i > len){
        cout << "位置不正确" << endl; 
    }
    else{
        x = data[i-1];
        for(j = i; j < len; j++){
            data[j-1] = data[j];
        }
        len--;
        cout << x << endl;
    }
}  
void List::PrintList(){
    for(int i = 0; i < len; i++){
        cout << data[i] << endl;
    }
}
int main()
{
    int i;
    int x;
    int m;
    char n;
    List q;
    while(1){
        cin >> n;
        if(n == 'I'){
            cin >> m;
            for(int j = 0; j < m; j++){
                cin >> i;
                cin >> x;
                q.Insert(i,x); 
            }
        }
        else if(n == 'S'){
            cin >> x;
            q.Find(x);
        }
        else if(n == 'G'){
            cin >> i;
            q.Get(i);
        }
        else if(n == 'D'){
            cin >> i;
            q.Delete(i);
        }
        else if(n == 'V'){
            q.PrintList();
        }
        else if(n == 'E'){
            return 0;
        }
        else{
            break;
        }
    }
    return 0;
}

真的找不出来哪里错误了


#include <iostream>

#define MAXSIZE 20

using namespace std;

class SeqList {
    public:
        SeqList():len_(0) {}

    public:
        void Insert(int pos, int val);
        int Delete(int pos);
        int Search(int val);
        int Get(int pos);
        void Print();

    private:
        int arr_[MAXSIZE];
        int len_;
};

void SeqList::Insert(int pos, int val) {
    if (len_ == MAXSIZE) throw "上溢";
    if (pos < 1 || pos > MAXSIZE) throw "位置不正确";

    for (int i = len_; i > pos - 1; i--) {
        arr_[i] = arr_[i - 1];
    }
    arr_[pos - 1] = val;

    len_++;
}

void SeqList::Print() {
    for (int i = 0; i < len_; i++) {
        cout << arr_[i] << endl;
    }
}

int SeqList::Delete(int pos) {
    if (len_ == 0) throw "下溢";
    if (pos < 1 || pos > len_ + 1) throw "位置不正确";

    int deletedVal = arr_[pos - 1];

    for (int i = pos; i < len_; i++) {
        arr_[i - 1] = arr_[i];
    }

    len_--;

    return deletedVal;
}

int SeqList::Get(int pos) {
    if (pos < 1 || pos > len_ + 1) throw "位置不正确";

    return arr_[pos - 1];
}

int SeqList::Search(int val) {
    bool isFind = false;
    int pos;

    for (int i = 0; i < len_; i++) {
        if (arr_[i] == val) {
            isFind = true;
            pos = i + 1;
            break;
        }
    }

    if (isFind == false) throw "None";

    return pos;
}

int main() {
    SeqList list;
    char command;
    int n, pos, val;

    while (cin >> command) {
        if (command == 'E') break;

        try {
            switch (command) {
                case 'I':
                    cin >> n;
                    for (int i = 0; i < n; i++) {
                        cin >> pos >> val;
                        list.Insert(pos, val);
                    }
                    break;

                case 'D':
                    cin >> pos;
                    cout << list.Delete(pos) << endl;
                    break;

                case 'S':
                    cin >> val;
                    cout << list.Search(val) << endl;
                    break;

                case 'G':
                    cin >> pos;
                    cout << list.Get(pos) << endl;
                    break;

                case 'V':
                    list.Print();
                    break;
            }
        } catch (const char* str) {
            cout << str << endl;
        }
    }

    return 0;
}