当前位置:网站首页>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 .
边栏推荐
- Opengauss active / standby architecture works with keeplive
- 在一个字符串里面统计给定字符串的个数
- Summary of common shortcut keys in idea
- “你“想当测试/开发程序员吗?努力发芽的我们......
- MySQL JPA support for JSON type data in database
- Tencent cloud hiflow scene connector
- 文章复现:超分辨率网络FSRCNN
- Learn how Baidu PaddlePaddle easydl realizes automatic animal recognition in aquarium
- 面试官:你确定Redis是单线程的进程吗?
- Interview question 01.05. Primary editing
猜你喜欢
随机推荐
C语言·指针
Day 013 one dimensional array exercise
Lecture 16 of project practice: using the open close principle to realize the commodity price rule engine
Software process that testers need to know
Summary of common shortcut keys in idea
Qlib tutorial - based on source code (II) local data saving and loading
【分布式开发】之 CAP 原则
Interview question 01.05. Primary editing
VLAN experiment
华为“天才少年”稚晖君又出新作,从零开始造“客制化”智能键盘
腾讯云HiFlow场景连接器
“你“想当测试/开发程序员吗?努力发芽的我们......
Niuke multi School Game 3 A, c+ weight segment tree
docker 本地搭建mysql主从
QT setting Icon
For newly installed PIP3, use no module named 'LSB_ Release 'problem
普通设备能不能接入TSN时间敏感网络?
Introduction to QT drawing system
LeetCode 2351. 第一个出现两次的字母
HRD 1. 一个简单而靠谱的HRD的检测方法








