谁能帮我改一改这个代码(关于C++顺序表的)?

需要实现
创建顺序表1:a b c d
值为a在表中的位置为:1
位置4的值为:d
删除第二个结点后顺序表:a c d
创建顺序表2:h i j k
合并后的表为:a c d h i j k
但我的代码实际实现的是:(附图)

img

#include<iostream>
using namespace std;
#define MAXSIZE 100
#define ERROR 0
typedef struct {
    int* elem;
    int length;
}S;

void InitList(S& L)
{
    L.elem = new int[MAXSIZE];
    L.length = 0;
}

int ETget(S L, int i)
{
    return L.elem[i - 1];
}

void Insert(S& L, char e, int i)
{
    for (int j = L.length - 1; j > i - 1;j--)
        L.elem[j + 1] = L.elem[j];
    L.elem[i] = e;
    ++L.length;
}

void Delete(S& L, int i)
{
    for (int j = i - 1; j < L.length;j++)
        L.elem[j] = L.elem[j + 1];
    --L.length;
}

void display(S& L)
{
    for (int i = 0;i < L.length;i++)
        cout << L.elem[i] << " ";
    cout << endl;
}

int Length(S L)
{
    return L.length;
}

int locate(S L, char e)
{
    for (int i = 0;i <= 3;i++)
        if (e == L.elem[i])
            return i;
}

void merg(S L1, S L2, S &L)
{
    L.length = L1.length + L2.length;
    for (int i = 0;i <= 2;i++)
        Insert(L, L1.elem[i],i);
    for (int j = 0;j <= 3;j++)
        Insert(L, L2.elem[j],j+3);
}

int main()
{
    S L1, L2, L;
    cout << "创建顺序表1:";
    InitList(L1);
    Insert(L1, 'a', 0);
    Insert(L1, 'b', 1);
    Insert(L1, 'c', 2);
    Insert(L1, 'd', 3);
    display(L1);
    cout << "值为a在表中的位置为:"<<locate(L1,'a') << endl;
    cout << "位置4的值为:"<<ETget(L1, 3)<<"\n";
    cout << "删除第二个结点后顺序表:";
    Delete(L1, 2);
    display(L1);
    cout << "创建顺序表2:";
    InitList(L2);
    Insert(L2, 'h', 0);
    Insert(L2, 'i', 1);
    Insert(L2, 'j', 2);
    Insert(L2, 'k', 3);
    display(L2);
    InitList(L);
    cout << "合并后的表为:";
    merg(L1, L2, L);
    display(L);

}

你题目的解答代码如下:

#include<iostream>
using namespace std;
#define MAXSIZE 100
#define ERROR 0
typedef struct {
    char* elem;
    int length;
}S;
void InitList(S& L)
{
    L.elem = new char[MAXSIZE];
    L.length = 0;
}
char ETget(S L, int i)
{
    return L.elem[i];
}
void Insert(S& L, char e, int i)
{
    for (int j = L.length - 1; j > i-1 ;j--)
        L.elem[j + 1] = L.elem[j];
    L.elem[i] = e;
    ++L.length;
}
void Delete(S& L, int i)
{
    for (int j = i; j < L.length;j++)
        L.elem[j] = L.elem[j + 1];
    --L.length;
}
void display(S& L)
{
    for (int i = 0;i < L.length;i++)
        cout << L.elem[i] << " ";
    cout << endl;
}
int Length(S L)
{
    return L.length;
}
int locate(S L, char e)
{
    for (int i = 0;i < L.length;i++)
        if (e == L.elem[i])
            return i;
}
void merg(S L1, S L2, S &L)
{
    for (int i = 0;i < L1.length;i++)
        Insert(L, L1.elem[i],i);
    for (int j = 0;j < L2.length;j++)
        Insert(L, L2.elem[j],j+L1.length);
}
int main()
{
    S L1, L2, L;
    cout << "创建顺序表1:";
    InitList(L1);
    Insert(L1, 'a', 0);
    Insert(L1, 'b', 1);
    Insert(L1, 'c', 2);
    Insert(L1, 'd', 3);
    display(L1);
    cout << "值为a在表中的位置为:"<<locate(L1,'a')+1 << endl;
    cout << "位置4的值为:"<<ETget(L1, 3)<<"\n";
    cout << "删除第二个结点后顺序表:";
    Delete(L1, 1);
    display(L1);
    cout << "创建顺序表2:";
    InitList(L2);
    Insert(L2, 'h', 0);
    Insert(L2, 'i', 1);
    Insert(L2, 'j', 2);
    Insert(L2, 'k', 3);
    display(L2);
    InitList(L);
    cout << "合并后的表为:";
    merg(L1, L2, L);
    display(L);
}

img

如有帮助,望采纳!谢谢!