一道数据结构的题有谁帮我看看

这是顺序表各个算法用C语言实现的代码,明天上完课以后大家对照书上的算法看看是如何用C语言实现的,然后将一个数据变成2个以上的结构体数据实现

https://blog.csdn.net/m0_63463510/article/details/125567286

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#define MAXLEN 100 //定义MAXLEN
typedef struct _Data
{
    int a;
    int b;
}DataType;
typedef struct
{
    DataType data[MAXLEN];
    int Length;
}SeqList;
 
 
void InitList(SeqList* L)
{
    L->Length = 0;
}
void CreateList(SeqList* L,int n)
{
    int i = 0;
    for (i = 0; i < n; i++)
    {
        scanf("%d%d", &L->data[i].a,&L->data[i].b);
    }
    L->Length = i;
}
 
int GetElem(SeqList* L, int i, DataType* x)
{
    if (i<1 || i>L->Length)
    {
        return 0;
    }
    else
    {
        *x = L->data[i - 1];
        return 1;
    }
}
int Locate(SeqList* L, DataType x)
{
    int i = 0;
    while (i < L->Length && (L->data[i].a != x.a || L->data[i].b != x.b))
    {
        i++;
    }
    if (i > L->Length)
    {
        return 0;
    }
    else
    {
        return i + 1;
    }
}
 
int InsElem(SeqList* L, int i, DataType x)
{
    int j = 0;
    if (L->Length >= MAXLEN)
    {
        printf("顺序表已满!");
        return -1;
    }
    if (i<1 || i>L->Length+1)
    {
        printf("插入位置出错");
        return 0;
    }
    if (i == L->Length + 1) //插入位置为表尾时
    {
        L->data[i - 1] = x;
        L->Length++;
        return 1;
    }
    for (j = L->Length - 1; j >= i - 1; j--)//插入位置为表中时
    {
        L->data[j + 1] = L->data[j];
    }
    L->data[i - 1] = x;
    L->Length++;
    return 1;
}
 
int DelElem(SeqList* L, int i, DataType* x)
{
    int j = 0;
    if (L->Length == 0)
    {
        printf("顺序表为空");
        return 0;
    }
    if (i<1 || i>L->Length)
    {
        printf("不存在第i个元素");
        return 0;
    }
    *x = L->data[i - 1];
    for (j = 1; j < L->Length; j++)
    {
        L->data[j - 1] = L->data[j];
    }
    L->Length--;
    return 1;
}
void DispList(SeqList* L)
{
    int i = 0;
    for (i = 0; i < L->Length; i++)
    {
        printf("%d,%d ", L->data[i].a,L->data[i].b);
    }
}
void  Menu()
{
    printf("                  顺序表的各种操作\n");
    printf("==================================================\n");
    printf("|              1——建立顺序表                   |\n");
    printf("|              2——插入元素                     |\n");
    printf("|              3——删除元素                     |\n");
    printf("|              4——按位置查找元素               |\n");
    printf("|              5——按元素值查找其在表中位置     |\n");
    printf("|              6——求顺序表的长度               |\n");
    printf("|              0——返回                         |\n");
    printf("==================================================\n");
    printf("请输入菜单号(0-6):");
}
int main()
{
    SeqList L;
    DataType x;
    int n, i, loc;
    char  ch1, ch2, a;
    ch1 = 'y';
    while (ch1 == 'y' || ch1 == 'Y')
    {
        Menu();
        scanf("%c", &ch2);
        getchar();
        switch (ch2)
        {
        case  '1':
            InitList(&L);
            printf("请输入建立线性表的个数:");
            scanf("%d", &n);
            CreateList(&L, n);
            printf("建立的线性表为:");
            DispList(&L);
            break;
        case  '2':
            printf("请输入要插入的位置:");
            scanf("%d", &i);
            printf("请输入要插入的元素值:");
            scanf("%d%d", &x.a,&x.b);
            if (InsElem(&L, i, x))
            {
                printf("已成功在第%d的位置上插入%d,插入后的线性表为:\n", i, x);
                DispList(&L);
            }
            else
                printf("输入插入的参数错误!");
            break;
        case  '3':
            printf("请输入要删除元素的位置:");
            scanf("%d", &i);
            if (DelElem(&L, i, &x))
            {
                printf("已成功在第%d的位置上删除(%d,%d),删除后的线性表为:\n", i, x.a,x.b);
                DispList(&L);
            }
            else
                printf("\n输入删除的参数错误!");
            break;
        case  '4':
            printf("请输入要查看表中元素位置(从1开始):");
            scanf("%d", &i);
            if (GetElem(&L, i, &x))
                printf("当前线性表第%d个元素的值为:(%d,%d)", i, x.a,x.b);
            else
                printf("输入的位置错误!");
            break;
        case  '5':
            printf("请输入要查找的元素值为:");
            scanf("%d%d", &x.a,&x.b);
            loc = Locate(&L, x);
            if (loc)
                printf("查找元素值为(%d,%d)的位置为:%d", x.a,x.b, loc);
            else
                printf("该表中无此元素!");
            break;
        case  '6':
            printf("当前线性表的长度为:%d", L.Length);
            break;
        case  '0':
            ch1 = 'n'; 
            break;
        default:
            printf("输入有误,请输入0-4进行选择!");
        }
        if (ch2 != '0')
        {
            printf("\n按回车键继续,按任意键返回主菜单!\n");
            a = getchar();
            if (a != '\xA')
            {
                getchar(); ch1 = 'n';
            }
        }
    }
}

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632