当前位置:网站首页>2.2 comprehensive application questions - sequence table
2.2 comprehensive application questions - sequence table
2022-07-28 01:43:00 【Wmpreturn】
subject 1: Order table delete elements
subject : Delete the element with the lowest value from the sequence table ( Suppose only ) And the value of the deleted element is returned by the function , The empty position is filled by the last element , If the sequence table is empty, an error message will be displayed and the operation will be exited .
/**
* @brief
* subject : Delete the element with the lowest value from the sequence table ( Suppose only )
* And the value of the deleted element is returned by the function ,
* The empty position is filled by the last element ,
* If the sequence table is empty, an error message will be displayed and the operation will be exited .
* Ideas :
* The values of the sequence table are entered by the keyboard
* hypothesis 0 No. data minimum , Compare with the following data , Finally, find the minimum value , Delete minimum , And fill in the last element here , Then delete the last element , Achieve the purpose of reducing the length .
*/
#include <stdio.h>
#define MaxSize 10 // Defines the maximum length of a linear table
typedef int ElemType;// Define data types
// Type definition of sequence table , The sequence table is Sqlist, Name of the sequence table :L
typedef struct {
ElemType data[MaxSize];// Elements of a sequence table
int length;// The current length of the sequence table
}SqList;
// Define delete minimum function
void Del_Min(SqList L, ElemType value)
{
//value Is the deleted value
if (L.length==0)
{
printf(" Wrong information \n");
value = 0;
}
value = L.data[0];
int pos = 0;
for (int i = 1; i < L.length; i++)
{
if (L.data[i]<value)
{
value = L.data[i];
pos = i;
}
}
if (pos < L.length-1)
{
L.data[pos]=L.data[L.length-1];// The empty position is filled by the last element
L.length--;
}
printf(" The minimum value in the sequence table is : %d\n",value);
printf(" The remaining elements of the sequence table are :\n");
for(int i = 0; i < L.length;i++){
printf("%d ",L.data[i]);
}
}
int main()
{
SqList L;
L.length = 0;
for (int i = 0; i < MaxSize; i++)
{
scanf("%d",&L.data[i]);
L.length++;
}
int a;
Del_Min(L,a);// Call function
printf("\n");
return 0;
}
Searched C Language version of the code , Everyone chose the definition bool Function of type , The return value is true Or is it false, however C Language only in c99 in the future , And add #include <stdbools> After this header , Can be used bool type .
In others' code , Also used. &—— quote .
Among them & Presentation reference , Instead of taking the address . The quotation is C++ Yes C An important supplement to . The reference of a variable is the alias of the variable , Speaking in a popular way, it's another name . Both point to the same address at the same time , A numeric variable , Another value will also change . It is also understandable if variables b It's a variable. a References to So no matter a,b Any one of the values changes , Another corresponding change , When declaring a reference , It must be initialized at the same time , That is, declare which variable it represents . Please note that : Because references are not independent variables , The compilation system does not assign storage units to it separately , therefore When creating a reference, only the declaration is undefined , Just declare its relationship with an original variable . After declaring a reference to a variable , During the execution of this function , This reference is always associated with the variable it represents , It can no longer be used as an alias for other variables .
however , It is a pity : pure C In language , There is no reference , In this case, pointers can be used instead of references . I don't want to use pointer variables yet , therefore , This writing failed .
边栏推荐
猜你喜欢

Article reproduction: super resolution network fsrcnn

PHP利用某些函数bypass waf探讨

Shutter -- password login registration interface

Discussion on PHP using some functions bypass WAF

Summary: Prometheus storage

Tencent cloud hiflow scene connector

登录功能实现

HRD 1. 一个简单而靠谱的HRD的检测方法

Leetcode 2351. the first letter that appears twice

Baidu PaddlePaddle easydl: when AI enters the factory, "small bearing" can also turn "big industry"
随机推荐
Leetcode 2347. the best poker hand
实现OCR语言识别Demo(二)- 图片及识别内容的展现和交互
Qlib教程——基于源码(二)本地数据保存与加载
Introduction and configuration of vsftpd
8000字讲透OBSA原理与应用实践
docker 本地搭建mysql主从
Hcip day 15
MySQL进阶--存储过程以及自定义函数
软件测试面试题:think_time的作用是什么?
HCIP第十五天
MPLS 隧道实验
Harmonyos 3 was officially released: Hongmeng mobile phones are smooth and safe, and Hongmeng terminals are often used
梳理 SQL 性能优化,收藏经典!
VLAN实验
内容bypass分享
Recursion related exercises
[C language] file operation
软件测试面试题:你们的性能测试需求哪里来?
likeshop外卖点餐系统【100%开源无加密】
【样式集合1】tab 栏