1、Description 编写算法,创建初始化容量为 LIST_INIT_SIZE 的顺序表 T,并 实现插入、删除、遍历操作。本题目给出部分代码,请补全内容。#include#include#define OK 1 #define ERROR 0#define LIST_INIT_SIZE 100#define LISTINCREMENT 10#define ElemType inttypedef structint *elem;int length;int listsize;SqList;int InitList_Sq(SqList if(_) printf(“The List is emp
2、ty!“); / 请填空elseprintf(“The List is: “);for(_) printf(“%d “,_); / 请填空printf(“n“);return OK;int ListInsert_Sq(SqList int a, i;ElemType e, x;if(_) / 判断顺序表是否创建成功printf(“A Sequence List Has Created.n“);while(1)printf(“1:Insert elementn2:Delete elementn3:Load all elementsn0:ExitnPlease choose:n“);scanf(“
3、%d“,switch(a)case 1: scanf(“%d%d“,if(_) printf(“Insert Error!n“); / 判断i 值是否合法,请填空else printf(“The Element %d is Successfully Inserted!n“, x); break;case 2: scanf(“%d“,if(_) printf(“Delete Error!n“); / 判断 i 值是否合法,请填空else printf(“The Element %d is Successfully Deleted!n“, e);break;case 3: Load_Sq(T);b
4、reak;case 0: return 1;输入格式测试样例格式说明:根据菜单操作:1、输入 1,表示要实现插入操作,紧跟着要输入插入的位置和元素,用空格分开2、输入 2,表示要实现删除操作,紧跟着要输入删除的位置3、输入 3,表示要输出顺序表的所有元素4、输入 0,表示程序结束输入样例11 211 32130输出样例A Sequence List Has Created.1:Insert element2:Delete element3:Load all elements0:ExitPlease choose:The Element 2 is Successfully Inserted!1:
5、Insert element2:Delete element3:Load all elements0:ExitPlease choose:The Element 3 is Successfully Inserted!1:Insert element2:Delete element3:Load all elements0:ExitPlease choose:The Element 3 is Successfully Deleted!1:Insert element2:Delete element3:Load all elements0:ExitPlease choose:The List is:
6、 2 1:Insert element2:Delete element3:Load all elements0:ExitPlease choose:顺序表的基本操作代码如下:#include#include#define OK 1#define ERROR 0#define LIST_INIT_SIZE 100#define LISTINCREMENT 10#define ElemType inttypedef int Status;typedef structint *elem;int length;int listsize;SqList;Status InitList_Sq(SqList
7、if (!L.elem) return OK; / 存储分配失败L.length = 0; / 空表长度为 0L.listsize = LIST_INIT_SIZE; / 初始存储容量return OK; / InitList_SqStatus ListInsert_Sq(SqList if (i L.length+1) return ERROR; / i 值不合法if (L.length = L.listsize) / 当前存储空间已满,增加容量ElemType *newbase = (ElemType *)realloc(L.elem,(L.listsize+LISTINCREMENT)*
8、sizeof (ElemType);if (!newbase) return ERROR; / 存储分配失败L.elem = newbase; / 新基址L.listsize += LISTINCREMENT; / 增加存储容量ElemType *q = / q 为插入位置for (p = p=q; -p) *(p+1) = *p;/ 插入位置及之后的元素右移*q = e; / 插入 e+L.length; / 表长增 1return OK; / ListInsert_SqStatus ListDelete_Sq(SqList if (iL.length) return ERROR; / i
9、值不合法p = / p 为被删除元素的位置e = *p; / 被删除元素的值赋给 eq = L.elem+L.length-1; / 表尾元素的位置for (+p; p#include#define OK 1#define ERROR 0#define LIST_INIT_SIZE 100#define LISTINCREMENT 10#define ElemType inttypedef int Status;typedef structint *elem;int length;int listsize;SqList;Status InitList_Sq(SqList if (!L.elem
10、) return OK; / 存储分配失败L.length = 0; / 空表长度为 0L.listsize = LIST_INIT_SIZE; / 初始存储容量return OK; / InitList_SqStatus ListInsert_Sq(SqList if (i L.length+1) return ERROR; / i 值不合法if (L.length = L.listsize) / 当前存储空间已满,增加容量ElemType *newbase = (ElemType *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof (Ele
11、mType);if (!newbase) return ERROR; / 存储分配失败L.elem = newbase; / 新基址L.listsize += LISTINCREMENT; / 增加存储容量ElemType *q = / q 为插入位置for (p = p=q; -p) *(p+1) = *p;/ 插入位置及之后的元素右移*q = e; / 插入 e+L.length; / 表长增 1return OK; / ListInsert_SqStatus ListDelete_Sq(SqList if (iL.length) return ERROR; / i 值不合法p = / p
12、 为被删除元素的位置e = *p; / 被删除元素的值赋给 eq = L.elem+L.length-1; / 表尾元素的位置for (+p; p#include#define ERROR 0#define OK 1 #define ElemType inttypedef struct LNodeint data;struct LNode *next;LNode,*LinkList;int CreateLink_L(LinkList int i;ElemType e;L = (LinkList)malloc(sizeof(LNode);L-next = NULL; / 先建立一个带头结点的单链
13、表q = (LinkList)malloc(sizeof(LNode);q = L;for (i=0; inext;if(_)printf(“The List is empty!“); / 请填空elseprintf(“The LinkList is:“);while(_) / 请填空printf(“%d “,p-data); _ / 请填空printf(“n“);return OK;int LinkInsert_L(LinkList int a,n,i;ElemType x, e;printf(“Please input the init size of the linklist:n“);s
14、canf(“%d“,printf(“Please input the %d element of the linklist:n“, n);if(_) / 判断链表是否创建成功,请填空printf(“A Link List Has Created.n“);LoadLink_L(T);while(1)printf(“1:Insert elementn2:Delete elementn3:Load all elementsn0:ExitnPlease choose:n“);scanf(“%d“,switch(a)case 1: scanf(“%d%d“,if(_) printf(“Insert Er
15、ror!n“); / 判断i 值是否合法,请填空else printf(“The Element %d is Successfully Inserted!n“, x); break;case 2: scanf(“%d“,if(_) printf(“Delete Error!n“); / 判断 i 值是否合法,请填空else printf(“The Element %d is Successfully Deleted!n“, e);break;case 3: LoadLink_L(T);break;case 0: return 1;输入格式测试样例格式说明:根据菜单操作:1、输入 1,表示要实现
16、插入操作,紧跟着要输入插入的位置和元素,用空格分开2、输入 2,表示要实现删除操作,紧跟着要输入删除的位置3、输入 3,表示要输出顺序表的所有元素4、输入 0,表示程序结束输入样例33 6 9314 122130输出样例Please input the init size of the linklist:Please input the 3 element of the linklist:A Link List Has Created.The LinkList is:3 6 9 1:Insert element2:Delete element3:Load all elements0:ExitP
17、lease choose:The LinkList is:3 6 9 1:Insert element2:Delete element3:Load all elements0:ExitPlease choose:The Element 12 is Successfully Inserted!1:Insert element2:Delete element3:Load all elements0:ExitPlease choose:The Element 3 is Successfully Deleted!1:Insert element2:Delete element3:Load all el
18、ements0:ExitPlease choose:The LinkList is:6 9 12 1:Insert element2:Delete element3:Load all elements0:ExitPlease choose:线性链表的基本操作如下:#include#include#define ERROR 0#define OK 1 #define ElemType inttypedef int Status;typedef struct LNodeint data;struct LNode *next;LNode,*LinkList;Status ListInsert_L(L
19、inkList p = L; int j = 0;while (p +j; if (!p | j i-1) return ERROR; / i 小于 1 或者大于表 长s = (LinkList)malloc(sizeof(LNode); / 生成新结点s-data = e; s-next = p-next; / 插入 L 中p-next = s;return OK; / LinstInsert_LStatus ListDelete_L(LinkList p = L;int j = 0;while (p-next +j;if (!(p-next) | j i-1) return ERROR;
20、/ 删除位置不合理q = p-next;p-next = q-next; / 删除并释放结点e = q-data;free(q);return OK; / ListDelete_L设计一个算法将两个非递减有序链表 A 和 B 合并成一个新的非递减有序链表 C。输入格式第一行:单链表 A 的元素个数第二行:单链表 A 的各元素(非 递减),用空格分开第三行:单链表 B 的元素个数第四行:单链表 B 的各元素(非 递减),用空格分开输出格式第一行:单链表 A 的元素列表第二行:单链表 B 的元素列表第三行:合并后单链表 C 的元素列表输入样例612 24 45 62 84 96415 31 75
21、86输出样例List A:12 24 45 62 84 96 List B:15 31 75 86 List C:12 15 24 31 45 62 75 84 86 96线性链表的基本操作如下:#include#include#define ERROR 0#define OK 1 #define ElemType inttypedef int Status;typedef struct LNodeint data;struct LNode *next;LNode,*LinkList;Status ListInsert_L(LinkList p = L; int j = 0;while (p
22、+j; if (!p | j i-1) return ERROR; / i 小于 1 或者大于表 长s = (LinkList)malloc(sizeof(LNode); / 生成新结点s-data = e; s-next = p-next; / 插入 L 中p-next = s;return OK; / LinstInsert_LStatus ListDelete_L(LinkList p = L;int j = 0;while (p-next +j;if (!(p-next) | j i-1) return ERROR; / 删除位置不合理q = p-next;p-next = q-nex
23、t; / 删除并释放结点e = q-data;free(q);return OK; / ListDelete_L设有一线性表 A=(a0,a1,., ai,.an-1),其逆 线性表定义为 A=( an-1,., ai,.,a1, a0),设计一个算法,将线性表逆置,要求线性表仍占用原线性表的空 间。输入格式第一行:输入 n,表示单链表的元素个数第二行:输入单链表的各元素,用空格分开输出格式第一行:输出单链表逆置前的元素列表第二行:输出单链表逆置后的元素列表输入样例832 97 54 65 35 84 61 75输出样例The List is:32 97 54 65 35 84 61 75 T
24、he turned List is:75 61 84 35 65 54 97 32#include #include #define OK 1#define ERROR 0#define STACK_INIT_SIZE 100 / 存储空间初始分配量#define STACKINCREMENT 10 / 存储空间分配增量typedef int SElemType; / 定义栈元素类型typedef int Status; / Status 是函数的类型,其值是函数结果状态代码,如 OK 等struct SqStackSElemType *base; / 在栈构造之前和销毁之后, base 的值
25、为 NULLSElemType *top; / 栈顶指针int stacksize; / 当前已分配的存 储空间,以元素为单位; / 顺序栈Status InitStack(SqStack p = _ /请填空if(_)printf(“The Stack is Empty!“); /请填空elseprintf(“The Stack is: “);p-;while(_) /请填空printf(“%d “, *p);_ /请填空printf(“n“);return OK;int main()int a;SqStack S;SElemType x, e;if(_) / 判断顺序表是否创建成功,请填空
26、printf(“A Stack Has Created.n“);while(1)printf(“1:Push n2:Pop n3:Get the Top n4:Return the Length of the Stackn5:Load the Stackn0:ExitnPlease choose:n“);scanf(“%d“,switch(a)case 1: scanf(“%d“, if(_) printf(“Push Error!n“); / 判断 Push 是否合法,请填空else printf(“The Element %d is Successfully Pushed!n“, x);
27、break;case 2: if(_) printf(“Pop Error!n“); / 判断 Pop 是否合法,请填空else printf(“The Element %d is Successfully Poped!n“, e);break;case 3: if(_)printf(“Get Top Error!n“); / 判断 Get Top是否合法,请填空else printf(“The Top Element is %d!n“, e);break;case 4: printf(“The Length of the Stack is %d!n“,_); /请填空break;case 5
28、: _ /请填空break;case 0: return 1;输入格式测试样例格式说明:根据菜单操作:1、输入 1,表示要实现 Push 操作,紧跟着输入要 Push 的元素2、输入 2,表示要实现 Pop 操作3、输入 3,返回栈顶元素4、输入 4,返回栈的元素个数5、输入 5,表示从栈顶到栈底输出栈的所有元素6、输入 0,表示程序结束输入样例121416534252220输出样例A Stack Has Created.1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5:Load the Stack0:ExitPlease
29、 choose:The Element 2 is Successfully Pushed!1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5:Load the Stack0:ExitPlease choose:The Element 4 is Successfully Pushed!1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5:Load the Stack0:ExitPlease choose:The Element 6 is Successfull
30、y Pushed!1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5:Load the Stack0:ExitPlease choose:The Stack is: 6 4 2 1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5:Load the Stack0:ExitPlease choose:The Top Element is 6!1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5
31、:Load the Stack0:ExitPlease choose:The Length of the Stack is 3!1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5:Load the Stack0:ExitPlease choose:The Element 6 is Successfully Poped!1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5:Load the Stack0:ExitPlease choose:The Stack
32、is: 4 2 1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5:Load the Stack0:ExitPlease choose:The Element 4 is Successfully Poped!1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5:Load the Stack0:ExitPlease choose:The Element 2 is Successfully Poped!1:Push 2:Pop 3:Get the Top 4:R
33、eturn the Length of the Stack5:Load the Stack0:ExitPlease choose:Pop Error!1:Push 2:Pop 3:Get the Top 4:Return the Length of the Stack5:Load the Stack0:ExitPlease choose:Description 创建一个空的循环队列,并实现入队、出 队、返回队列的长度、返回队头元素、队列的遍历等基本算法。请将下面的程序补充完整。#include #include #define OK 1#define ERROR 0typedef int St
34、atus; / Status 是函数的类型,其值是函数结果状态代码,如 OK 等typedef int QElemType;#define MAXQSIZE 100 / 最大队列长度(对于循环队列,最大队列长度要减 1)typedef structQElemType *base; / 初始化的动态分配存储空间int front; / 头指针,若队列不空,指向队列头元素int rear; / 尾指针,若队列不空,指向队列尾元素的下一个位置SqQueue;Status InitQueue(SqQueue 否则返回 ERROR/ 请补全代码Status GetHead(SqQueue Q, QEle
35、mType i=Q.front;if(_)printf(“The Queue is Empty!“); /请填空elseprintf(“The Queue is: “);while(_) /请填空printf(“%d “,_ ); /请填空i = _; /请填空printf(“n“);return OK;int main()int a;SqQueue S;QElemType x, e;if(_) / 判断顺序表是否创建成功,请填空printf(“A Queue Has Created.n“);while(1)printf(“1:Enter n2:Delete n3:Get the Front
36、n4:Return the Length of the Queuen5:Load the Queuen0:ExitnPlease choose:n“);scanf(“%d“,switch(a)case 1: scanf(“%d“, if(_) printf(“Enter Error!n“); / 判断入队是否合法,请填空else printf(“The Element %d is Successfully Entered!n“, x); break;case 2: if(_) printf(“Delete Error!n“); / 判断出队是否合法,请填空else printf(“The El
37、ement %d is Successfully Deleted!n“, e);break;case 3: if(_)printf(“Get Head Error!n“); / 判断 Get Head 是否合法,请填空else printf(“The Head of the Queue is %d!n“, e);break;case 4: printf(“The Length of the Queue is %d!n“,_); /请填空break;case 5: _ /请填空break;case 0: return 1;输入格式测试样例格式说明:根据菜单操作:1、输入 1,表示要实现入队操作,
38、紧跟着输入要入队的元素2、输入 2,表示要实现出队操作3、输入 3,返回队头元素4、输入 4,返回队列的元素个数5、输入 5,表示从队头到队尾输出队的所有元素6、输入 0,表示程序结束输入样例11121352350输出样例A Queue Has Created.1:Enter 2:Delete 3:Get the Front 4:Return the Length of the Queue5:Load the Queue0:ExitPlease choose:The Element 1 is Successfully Entered!1:Enter 2:Delete 3:Get the Fro
39、nt 4:Return the Length of the Queue5:Load the Queue0:ExitPlease choose:The Element 2 is Successfully Entered!1:Enter 2:Delete 3:Get the Front 4:Return the Length of the Queue5:Load the Queue0:ExitPlease choose:The Element 3 is Successfully Entered!1:Enter 2:Delete 3:Get the Front 4:Return the Length
40、 of the Queue5:Load the Queue0:ExitPlease choose:The Queue is: 1 2 3 1:Enter 2:Delete 3:Get the Front 4:Return the Length of the Queue5:Load the Queue0:ExitPlease choose:The Element 1 is Successfully Deleted!1:Enter 2:Delete 3:Get the Front 4:Return the Length of the Queue5:Load the Queue0:ExitPleas
41、e choose:The Head of the Queue is 2!1:Enter 2:Delete 3:Get the Front 4:Return the Length of the Queue5:Load the Queue0:ExitPlease choose:The Queue is: 2 3 1:Enter 2:Delete 3:Get the Front 4:Return the Length of the Queue5:Load the Queue0:ExitPlease choose:顺序栈的基本操作如下:#include #include #define OK 1#de
42、fine ERROR 0#define STACK_INIT_SIZE 100 / 存储空间初始分配量#define STACKINCREMENT 10 / 存储空间分配增量typedef int SElemType; / 定义栈元素类型typedef int Status; / Status 是函数的类型,其值是函数结果状态代码,如 OK 等struct SqStackSElemType *base; / 在栈构造之前和销毁之后, base 的值为 NULLSElemType *top; / 栈顶指针int stacksize; / 当前已分配的存 储空间,以元素为单位; / 顺序栈Stat
43、us InitStack(SqStack if(!S.base) return ERROR;S.top=S.base;S.stacksize=STACK_INIT_SIZE;return OK;Status Push(SqStack if(!S.base) return ERROR;S.top=S.base+S.stacksize;S.stacksize+=STACKINCREMENT;*S.top+=e;return OK;Status Pop(SqStack e=*-S.top;return OK;Status GetTop(SqStack S,SElemType e=*(S.top-1)
44、;return OK;int StackLength(SqStack S) / 返回栈 S 的元素个数int i;i=S.top-S.base;return i;Status StackTraverse(SqStack S)/ 从栈顶到栈底依次输出栈中的每个元素SElemType *p = (SElemType *)malloc(sizeof(SElemType); p = S.top; if(S.top=S.base)printf(“The Stack is Empty!“); elseprintf(“The Stack is: “);p-;while(p=S.base) printf(“%
45、d “, *p);p-; printf(“n“);return OK;利用顺序栈的基本操作算法, 编写满足下列要求的数制转换 程序:对于输入的任意一个非负十进制整数,打印输出与其等 值的八进制数。输入格式第一行:输入一个非负的十进制整数输出格式第一行:与输入等值的八进制数输入样例15输出样例17Description 利用栈编写满足下列要求的括号匹配检验程序:假设表达式中允许包含两种括号:圆括号和方括号,其嵌套的 顺序随意,即 ()或()等为正确的格式,(或()或()均为不正确的格式。输入一个包含上述括号的表达式, 检验 括号是否配对。本题给出部分check()函数,要求将 check()函数 补充完整,并完成整个程序。typedef char SElemType;#include“malloc.h“ #include“stdio.h“#include“math.h“#include“stdlib.h“ / exit()#define OK 1#define ERROR 0#define TRUE 1#define FALSE 0typedef int Status; / Status 是函数的类型,其值是函数结果状态代码,如 OK 等#define STACK_INIT_SIZE 10 / 存储空间初始分配量#define STACKINCREMENT 2