artais 2022-03-28 12:24 采纳率: 61.1%
浏览 59
已结题

该段代码如何补充完整,使其能够按要求运行

#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 10 //最大长度
typedef char ElemType;
typedef struct {
ElemType* elem; //指向顺序存储的线性表的基地址
unsigned int uListLength; //线性表的当前长度
unsigned int uListSize; //线性表的最大长度

}SqList;
//线性表采用顺序存储实现,基本操作函数声明如下:
bool InitList(SqList& L, unsigned int uListSize); //线性表初始化
bool DestroyList(SqList& L); //销毁线性表
//下面是三个在表尾插入一个数据元素的函数声明
bool ListTailInsertPassByValue(SqList L, ElemType e);
bool ListTailInsertPassByRef(SqList& L, ElemType e);
bool ListTailInsertPassByPoint(SqList* L, ElemType e);
int main()
{
SqList sqList;
int i = 0;
char cTemp = 0;
ElemType eTemp = '1';
InitList(sqList, MAXSIZE);
eTemp = '1';
ListTailInsertPassByValue(sqList, eTemp);
eTemp = '2';
ListTailInsertPassByRef(sqList, eTemp);
eTemp = '3';
ListTailInsertPassByPoint(&sqList, eTemp);
DestroyList(sqList);
}

//线性表初始化,InitList,代码略,参考教材或PPT代码
//销毁线性表,DestroyList,代码略,参考教材或PPT代码
//三个在顺序表尾巴插入数据元素函数的实现代码
bool ListTailInsertPassByValue(SqList L, ElemType e) {
if ((L.elem) && (L.uListLength < L.uListSize))
{ L.elem[L.uListLength] = e; L.uListLength++;
return true; }
else
return false;
}
bool ListTailInsertPassByRef(SqList& L, ElemType e) {
if ((L.elem) && (L.uListLength < L.uListSize))
{ L.elem[L.uListLength] = e; L.uListLength++;
return true; }
else
return false; }
bool ListTailInsertPassByPoint(SqList* L, ElemType e) {
if (!L)
return false;
if ((L->elem) && (L->uListLength < L->uListSize))
{ L->elem[L->uListLength] = e; L->uListLength++;
return true; }
else
return false; }

  • 写回答

1条回答 默认 最新

  • stone_wangzx 2022-03-28 14:18
    关注
    
    #include <stdio.h>
    #include <stdlib.h>
    #define MAXSIZE 10 //最大长度
    typedef char ElemType;
    typedef struct {
        ElemType* elem; //指向顺序存储的线性表的基地址
        unsigned int uListLength; //线性表的当前长度
        unsigned int uListSize; //线性表的最大长度
    
    }SqList;
    //线性表采用顺序存储实现,基本操作函数声明如下:
    bool InitList(SqList& L, unsigned int uListSize); //线性表初始化
    bool DestroyList(SqList& L); //销毁线性表
    //下面是三个在表尾插入一个数据元素的函数声明
    bool ListTailInsertPassByValue(SqList L, ElemType e);
    bool ListTailInsertPassByRef(SqList& L, ElemType e);
    bool ListTailInsertPassByPoint(SqList* L, ElemType e);
    int main()
    {
        SqList sqList;
        int i = 0;
        char cTemp = 0;
        ElemType eTemp = '1';
        InitList(sqList, MAXSIZE);
        eTemp = '1';
        ListTailInsertPassByValue(sqList, eTemp);
        eTemp = '2';
        ListTailInsertPassByRef(sqList, eTemp);
        eTemp = '3';
        ListTailInsertPassByPoint(&sqList, eTemp);
        DestroyList(sqList);
    
        return 0;
    }
    
    //线性表初始化,InitList,代码略,参考教材或PPT代码
    bool InitList(SqList& L, unsigned int uListSize)
    {
        L.elem = new ElemType[uListSize];
        L.uListLength = 0;
        L.uListSize = uListSize;
        return true;
    }
    //销毁线性表,DestroyList,代码略,参考教材或PPT代码
     bool DestroyList(SqList& L)
     {
         delete[] L.elem;
         L.elem = nullptr;
         L.uListLength = 0;
         L.uListSize = 0;
         return true;
     }
    //三个在顺序表尾巴插入数据元素函数的实现代码
    bool ListTailInsertPassByValue(SqList L, ElemType e) {
        if ((L.elem) && (L.uListLength < L.uListSize))
        {
            L.elem[L.uListLength] = e; L.uListLength++;
            return true;
        }
        else
            return false;
    }
    bool ListTailInsertPassByRef(SqList& L, ElemType e) {
        if ((L.elem) && (L.uListLength < L.uListSize))
        {
            L.elem[L.uListLength] = e; L.uListLength++;
            return true;
        }
        else
            return false;
    }
    bool ListTailInsertPassByPoint(SqList* L, ElemType e) {
        if (!L)
            return false;
        if ((L->elem) && (L->uListLength < L->uListSize))
        {
            L->elem[L->uListLength] = e; L->uListLength++;
            return true;
        }
        else
            return false;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月8日
  • 已采纳回答 3月31日
  • 创建了问题 3月28日

悬赏问题

  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能