源代码:
//
// main.c
// Sxsearch
// 程序目的:在r[n]数组中顺序查找关键字等于kx的记录
// Created by zhen7216 on 2016/12/4.
// Copyright © 2016年 chenzhen. All rights reserved.
//
#include <stdio.h>
#define max 7
int searchList[max] = {0, 13, 25, 16, 23, 57, 66};
//在r[n]数组中查找
int sxSearch(int r[], int n, int kx) {
int i;
r[0] = kx;//在下标为0处设置监视哨
i = n - 1;
while(r[i] != kx)
i--;
return i;//返回查找的位置
}
int main() {
int key;
printf("please input the data you want to search:\n");
scanf("%d", &key);
if (sxSearch(searchList, max, key) != 0)
printf("the data is found\n");
else
printf("the data is not found\n");
}