当前位置:网站首页>Sequence table Curriculum
Sequence table Curriculum
2022-06-23 07:58:00 【Shixiansen is crazy】
The experiment purpose :
Master the basic operation of linear table : Insert 、 Delete 、 Find the implementation on the sequential storage structure .
experimental condition :
VC++6.0, A computer
Content :
Build an orderly sequence table , And implement the following operations :
- 1. Put elements x Insert into the table and keep it in order ;
- 2. The lookup value is x The elements of , If found, delete it ;
- 3. Output the value of each element in the table .
Algorithmic thought :
/* Build an orderly sequence table , And implement the following operations : C Language description 1. Put elements x Insert into the table and keep it in order ; 2. The lookup value is x The elements of , If found, delete it ; 3. Output the value of each element in the table .*/
#include <stdio.h>
#define MAXSIZE 20
// Create sequence table structure
typedef struct seqlist
{
int elem[MAXSIZE];
int length;
}SeqList;
// Initialization sequence table
void IniList(SeqList *l)
{
l->length = 0;
}
// Insert the elements into the table and keep them in order
void InsList(SeqList *l, int n)
{
int i = 0, j;
while (n > l->elem[i] && i < l->length)
i++;
for (j = l->length - 1; j >= i; j--)
l->elem[j+1] = l->elem[j];
l->elem[i] = n;
(l->length)++;
}
// Find out whether an element is in the table
int CheckList (SeqList l, int n)
{
int i = 0;
while (i < l.length && n != l.elem[i])
i++;
if (i < l.length)
return i;
return -1;
}
// Find and delete an element
void DelList (SeqList *l, int n)
{
int j;
if (n < 0 || n > l->length - 1)
{
printf (" empty ! Please check whether the value is in the sequence table !\n");
return ;
}
for (j = n + 1; j < l->length; j++)
l->elem[j-1] = l->elem[j];
(l->length)--;
}
// Output the elements in the table
void PrintList(SeqList l)
{
int i;
for (i = 0; i < l.length; i++)
{
printf ("%d ", l.elem[i]);
}
printf ("\n");
}
int main ()
{
SeqList list;
int index, element;
IniList(&list); // initialization
printf (" Please enter the first element : "); // Input elements
scanf ("%d", &element);
printf (" Please enter another element ( With 0 ending ): ");
while (0 != element)
{
InsList(&list, element); // Insert elements
scanf ("%d", &element);
}
PrintList(list); // List output element
printf (" Please enter the element to be deleted : ");
scanf ("%d", &element);
index = CheckList(list, element); // Look for the element
if (-1 == index)
{
printf ("%d Not in the sequence table \n", element);
}
else
DelList(&list, index); // If you find , Then delete the element
PrintList(list); // Output each element in the list again
return 0;
}
边栏推荐
- 30 sets of report templates necessary for the workplace, meeting 95% of the report needs, and no code is required for one click application
- 顺序表课设
- 通过端口查文件
- 数学知识:欧拉函数—欧拉函数
- Take you to tiktok. That's it
- openni. utils. OpenNIError: (OniStatus.ONI_STATUS_ERROR, b‘DeviceOpen using default: no devices found‘
- Talk about routing design in service governance
- What is edge cloud?
- INT 104_LEC 06
- @Controller和@RestController的区别?
猜你喜欢

VTK. Le bouton gauche de la souris JS glisse pour changer le niveau et la largeur de la fenêtre

Eureka service registration and discovery

图像分割-改进网络结构

Online JSON to CSharp (c) class tool

Introduction to Excel VBA and practical examples

Deploy kubersphere in kubernetes
![[veusz] import 2D data in CSV](/img/22/467139f5a83ce9e88a57ced732d4d6.png)
[veusz] import 2D data in CSV

Can you think of a better way to solve the problem of string inversion?

Qt工程报错:-1: error: Cannot run compiler ‘clang++‘. Output:mingw32-make.exe

Interview questions of a company in a certain month of a certain year (1)
随机推荐
Match 56 de la semaine d'acwing [terminé]
Chain tour airship development farmers' world chain tour development land chain tour development
Guava Cache 使用小结
Pseudocode specification, pseudocode online editor,
Unity picture loading and saving
For loop of go language foundation
The eighth experiment of hcip Road
Vs problems when connecting to SQL myconn OPen(); cannot execute
[try to hack] IP address
深度学习------不同方法实现lenet-5模型
快速排序 + 冒泡排序 + 插入排序 + 選擇排序
Quick sort + bubble sort + insert sort + select sort
qt 不规则图形 消除锯齿
imperva-查找正则匹配超时的方法
Interview questions of a company in a certain month of a certain year (1)
浅析 Open API 设计规范
MySQL慢查询记录
快速排序 + 冒泡排序 + 插入排序 + 选择排序
SQL注入常用到的绕过方式-ctf
Gif verification code analysis