当前位置:网站首页>Operation 7.19 sequence table
Operation 7.19 sequence table
2022-07-25 09:35:00 【Unknown college student M】
1. Finish modifying functions by value
function code
// Modify by value
int listUpdateValue(seqList *S,datatype old_e,datatype new_e)
{
int pos=listSearchValue(S,old_e);
if(pos>=0)
{
S->data[pos]=new_e;
printf(" Modification successful \n");
return 0;
}
else
{
printf(" Modification failed \n");
return -1;
}
}
Test code
#include "seqlist.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
seqList *S = listCreate();
if(NULL==S)
{
return -1;
}
// Call add function
listAdd(S,7);listAdd(S,2);listAdd(S,5);
listAdd(S,6);listAdd(S,4);listAdd(S,4);
listAdd(S,4);listAdd(S,7);listAdd(S,8);
listShow(S);
// Call the modify by value function
listUpdateValue(S,6,9);
listShow(S);
listUpdateValue(S,1,3);
listShow(S);
}
Running results
The initial data element of the sequence table is 7 2 5 6 4 4 4 7 8
Set data element as 6 The element of is changed to 9, Modification successful
Set data element as 1 The element of is changed to 3, Modification failed

2. Complete the search function by position , Return the found data
function code
// Find by location
datatype listSearchPos(seqList *S,int pos)
{
if(pos<0||pos>=S->len)
{
printf(" Illegal location , To find the failure \n");
return -1;
}
printf(" Find success , Indexes %d The element in position is %d\n",pos,S->data[pos]);
return S->data[pos];
}
Test code
#include "seqlist.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
seqList *S = listCreate();
if(NULL==S)
{
return -1;
}
// Call add function
listAdd(S,7);listAdd(S,2);listAdd(S,5);
listAdd(S,6);listAdd(S,4);listAdd(S,4);
listAdd(S,4);listAdd(S,7);listAdd(S,8);
listShow(S);
// Call the bitwise lookup function
listSearchPos(S,2);
listSearchPos(S,9);
}
Running results
The initial data element of the sequence table is 7 2 5 6 4 4 4 7 8
Search index is 2 The elements of , Find success , The data element is 5
Search index is 9 The elements of , To find the failure

3. Complete the use of selective sorting to achieve the descending order of the sequence table
function code
// Selection sort
void listSort2(seqList *S)
{
for(int i=0;i<S->len-1;i++)
{
datatype max =S->data[i];
int index=i;
for(int j=i+1;j<S->len;j++)
{
if(max<S->data[j])
{
index=j;
max=S->data[j];
}
}
if(index!=i)
{
datatype temp = S->data[index];
S->data[index]=S->data[i];
S->data[i]=temp;
}
}
printf(" Sort success \n");
}
Test code
#include "seqlist.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
seqList *S = listCreate();
if(NULL==S)
{
return -1;
}
// Call add function
listAdd(S,7);listAdd(S,2);listAdd(S,5);
listAdd(S,6);listAdd(S,4);listAdd(S,4);
listAdd(S,4);listAdd(S,7);listAdd(S,8);
listShow(S);
// Call select sort
listSort2(S);
listShow(S);
}
Running results
The initial data element of the sequence table is 7 2 5 6 4 4 4 7 8
After sorting, the result is 8 7 7 6 5 4 4 4 2

Source code link
https://github.com/WeiJiaM/seqlist.git
边栏推荐
猜你喜欢

类(2) 和 协议

sqli-labs Basic Challenges Less11-22

Week summary

Idea practical tips --- now change pom.xml (red) to pom.xml (blue)

uni-app如何获取位置信息(经纬度)

How to deploy the jar package to the server? Note: whether the startup command has nohup or not has a lot to do with it

TCP network application development process

PHP网站设计思路

Data control language (DCL)

@3-2 CCF 2020-12-2 期末预测之最佳阈值
随机推荐
Redis installation (Ubuntu)
梦想启航(第一篇博客)
语音聊天app源码-钠斯网络源码出品
Indexes, views and transactions of MySQL
Flex layout syntax and use cases
[GYCTF2020]Node Game
Swagger2显示get接口有问题,加注解就能解决
【代码源】每日一题 添加括号
Jspdf generates PDF files. There is a problem of incomplete files. Files are downloaded in the background, but not in the foreground
初始Flask以及简单地上手应用
Analysis of five data structure principles of redis
*6-2 CCF 2015-03-3 节日
Numpy array attribute, shape changing function, basic operation
浏览器访问swagger失败,显示错误ERR_UNSAFE_PORT
单例模式(Singleton)
js中map()函数的使用
如何将Jar包部署到服务器,注:启动命令有无nohup有很大关系
How to write Android switching interface with kotlin
【代码源】每日一题 非递减01序列
[GKCTF 2021]easynode