当前位置:网站首页>顺序表查找
顺序表查找
2022-06-23 03:44:00 【@风景邮递Yuan】
顺序查找
int Sequential_Search ( int *a, int n, int key ) {
int i;
for (i = 1; i <= n; i++) {
if (a[i] == key )
return i;
}
return 0;
}int Sequential_Search2 ( int *a, int n, int key ) {
int i;
/* 设 置 a[0] 为 关 键 字 值 , 我 们 称 之 为 “ 哨 兵 ” */
a[0] = key ;
/* 循 环 从 数 组 尾 部 开 始 */
i = n;
while (a[i] != key ) {
i - -;
}
/* 返 回 0 则 说 明 查 找 失 败 */
return i;
}边栏推荐
猜你喜欢
随机推荐
mysql如何删除表的一行数据
January 17, 2022: word rule II. Give you a pattern and a character
JS Part 4
[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation
数据交易怎样实现
冒泡排序法
[advanced Android] kotlin delegate attribute
关于sql语句的问题
浅析2022年物联网现状
Stress testing with locust on rainbow
虫子 STM32 高级定时器 (哈哈我说实话硬件定时器不能体现实力,实际上想把内核定时器发上来的,一想算了,慢慢来吧)
新版kali切换最高账户
炫酷鼠标跟随动画js插件5种
怎么使用Shell脚本实现监测文件变化
What is the difference between the poll () method and the remove () method?
redis 精讲系列介绍八 - 淘汰策略
【LeetCode】23. Merge K ascending linked lists
[tcapulusdb knowledge base] [list table] example code for deleting the data at the specified location in the list
怎么用好MySQL索引
Weekly Postgres world news 2022w02









