P24.CPP
上传用户:chaiyuqiu
上传日期:2022-08-03
资源大小:27k
文件大小:1k
源码类别:

数据结构

开发平台:

C/C++

  1. int SeqSearch ( int a[], const int n, const int x ) {
  2.     int i = 0;
  3.     while ( i < n && a[i] != x ) i++;
  4.     if ( i == n ) return -1;
  5.     return i;
  6. }
  7. #include <iostream.h>
  8. void main() {
  9.     static int a[10] = {1,2,3,4,5,6,7,8,9,10};
  10.     int i = SeqSearch ( a, 10, 6);
  11.     cout << "The location is: " << i << endl;
  12. }