当前位置:网站首页>Code implementation of sequence table
Code implementation of sequence table
2022-04-22 16:29:00 【qq_ two billion seven hundred and thirty-seven million thirty-f】
Code implementation of sequence table
// The order sheet .cpp : This file contains "main" function . Program execution will start and end here .
#include <iostream>
using namespace std;
#define OK 1
#define ERROR 0
#define MAXSIZE 20
#define TRUE 1
#define FALSE 0
typedef int Status;
typedef int ElemType;
typedef struct {
ElemType data[MAXSIZE];
int length;
}SqList;
Status InitList(SqList* L)
{
if (L == NULL)return ERROR;
L->length = 0;
return OK;
}
Status ClearList(SqList* L)
{
if (L == NULL)return ERROR;
L->length = 0;
return OK;
}
Status isListEmpty(SqList* L)
{
if (L == NULL)return TRUE;
if (L->length == 0)return TRUE;
return ERROR;
}
int ListLength(SqList* L)
{
return L->length;
}
Status ListInsert(SqList* L, int index, const ElemType e)
{
if ((index >= 1) && (L->length < MAXSIZE))
{
if (index <= L->length)
{
for (int k = L->length - 1; k >= index - 1; k--)
L->data[k + 1] = L->data[k];
}
L->data[index - 1] = e;
L->length++;
return OK;
}
return ERROR;
}
Status ListDelete(SqList* L,int index,ElemType* e)
{
if (L->length == 0)return ERROR;
if (index<1 || index>L->length)return ERROR;
*e = L->data[index - 1];
if (index < L->length) {
for(int k=index;k<L->length;k++)
L->data[k - 1] = L->data[k];
L->length--;
return OK;
}
}
Status visit(ElemType e)
{
printf("%d->", e);
return OK;
}
Status ListTraverse(SqList* L)
{
for (int i = 0; i < L->length; i++)
visit(L->data[i]);
printf("\r\n");
return OK;
}
Status GetElem(SqList* L, int index, ElemType* e)
{
if (L->length == 0 || index<1 || index>L->length)
return ERROR;
*e = L->data[index - 1];
return OK;
}
int main()
{
SqList L;
ElemType e;
Status ret;
int j, k;
ret = InitList(&L);
printf(" initialization L after :L.length=%d\n", L.length);
for (j = 1; j <= 5; j++)
ret = ListInsert(&L, 1, j);
ListTraverse(&L);
ret = isListEmpty(&L);
printf("L Is it empty :%d(1: empty 0: no )\n", ret);
ClearList(&L);
ret = isListEmpty(&L);
printf("L Is it empty %d(1: empty 0: no )\n", ret);
for (j = 1; j <= 10; j++)
ret = ListInsert(&L, 1, j);
ListTraverse(&L);
ListInsert(&L, 1, 0);
ListTraverse(&L);
GetElem(&L, 5, &e);
printf(" The fifth element is %d\n", e);
k = ListLength(&L);
for (j = k + 1; j >= k; j--) {
ret = ListDelete(&L, j, &e);
if (ret == ERROR)
printf(" Delete the first %d Data failed \n", j);
else
printf(" Delete the first %d Data success :%d\n", j, e);
}
ListTraverse(&L);
ListDelete(&L, 5, &e);
printf(" Delete the first %d Data success ;%d\n", 5, e);
return 0;
}
版权声明
本文为[qq_ two billion seven hundred and thirty-seven million thirty-f]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221626400878.html
边栏推荐
- 3D reconstruction of power conductor based on LIDAR point cloud
- 记一次对oracle数据库表空间异常增长的分析和处理
- Win10安装MySQL5.7(图文详解)
- Ten thousand yuan gift pool! Play "Lighthouse" award-winning essay attack
- 蓝桥杯练习020
- Where is the dimension association table of Flink SQL? 800W dimension table
- 经销商组团检阅欧尚Z6:为高能产品力点赞
- C language insertion sort
- TCP / IP protocol IV TCP protocol (I) - Theory + practice to make it clear to you
- 【操作教程】国标GB28181平台EasyGBS如何开启语音对讲功能?
猜你喜欢

Algorithm:实现LDA的Gibbs Gauss采样(绘制多图subplot)

动态拖动两个div的宽度

Transforme结构:位置编码 | Transformer Architecture: The Positional Encoding

Performance evaluation of rust asynchronous framework
![[b01lers2020]Life on Mars](/img/4c/c21f74153d6a668349d39f54e95e26.png)
[b01lers2020]Life on Mars

Calculation method of numerator and denominator of system driven by stepping servo motor for rotation angle control

Talk about the general problem of substitution between TL431 and az431 (personal experience)

步进伺服电机驱动的系统用于旋转角度控制分子分母计算方法

1016 Phone Bills (25 分) 测试点1,2

Redis cache hit rate
随机推荐
蓝桥杯练习018
Industry research: the development trend of domestic databases from the perspective of manufacturers
Performance evaluation of rust asynchronous framework
国美新动作“真选”“严选”赋能 多维度护航品质消费
Win10安装MySQL5.7(图文详解)
[arm assembly] how to judge the input data?
使用EasyGBS后更换为EasyCVR,更改端口为10000,报错404是什么原因?
引用拷贝,深拷贝,浅拷贝
【无标题】
【ARM汇编】如何对键入数据做判断?
MINIUSB pin interface pin definition
SolidWorks插入内六角螺丝
Dynamically drag the width of two divs
Huawei machine test questions -- hj54 expression evaluation
DM8:win7+php7.3.4(phpstudy)+apache(phpstudy)+dm8.1-2-84环境搭建
Greenplum [environment construction 05] GP latest version V6 20.3 configuration and installation verification (description of kernel parameters + initialization parameters)
蓝桥杯练习019
7寸触摸屏屏幕校准参数设置
Introduce file path problem-$_ Server ['document_root'] represents the root directory of the website
Talk about the general problem of substitution between TL431 and az431 (personal experience)