当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Talk about routing design in service governance

YGG Spain subdao Ola GG officially established

ArcMap批量删除距离较近的点

30 sets of report templates necessary for the workplace, meeting 95% of the report needs, and no code is required for one click application

ArcMap batch delete points closer
![[try to hack] IP address](/img/ab/ed91f3094ac913a0d79448a2d19015.png)
[try to hack] IP address

INT 104_LEC 06

The road to hcip MPLS

Matlab随机波动率SV、GARCH用MCMC马尔可夫链蒙特卡罗方法分析汇率时间序列

To conquer salt fields and vegetable fields with AI, scientific and technological innovation should also step on the "field"
随机推荐
Apache Solr 任意文件读取复现
Guava Cache 使用小结
一秒钟查看一次文件,并将文件最后一行内容结果发送至syslog服务器
C#打印缩放
unity 音频可视化方案
SQL注入常用到的绕过方式-ctf
Left multiply right multiply matrix problem
Tri rapide + Tri par bulle + Tri par insertion + Tri par sélection
Gif verification code analysis
Unity picture loading and saving
Quick sort + bubble sort + insert sort + select sort
Talk about routing design in service governance
MFC Radio Button分组
2022山东大学软件学院软件项目管理期末考试(回忆版)
Microsoft Exchange – prevent network attacks
浅谈ThreadLocal和InheritableThreadLocal,源码解析
Socket programming (multithreading)
Vs problems when connecting to SQL myconn OPen(); cannot execute
职场必备的30套报表模板,满足95%的报表需求,一键套用无需代码
The road to hcip MPLS