#include <iostream>
using namespace Std;
#define MAXSIZE 100
Class date{
Public
int date[maxsize + 1]; /* stored in 1 to n subscript storage, empty the location labeled 0 */
};
int Mindsearch (date&a, int k, int n); /* Search by two points */
int Sequentialsearch (Date &a, int k, int n); /* Find sequentially */
int main () {
Date A;
int i,n,k,j;
CIN >> N;
for (i = 1; i < n + 1; i++)
CIN >> A.date[i];
cout << "Enter the number of searches K:";
Cin >> K;
J=sequentialsearch (A, K, N);
if (j = = 0)
cout << "Search by order, not found" << K << Endl;
Else
cout << "Find in order" << K << "at the first" << J << "position" << Endl;
j = Mindsearch (A, K, N);
if (j = = 0)
cout << "Two-point search, not found" << K << Endl;
Else
cout << "binary search" << K << "at the first" << J << "position" << Endl;
return 0;
}
int Sequentialsearch (Date &a, int k,int n) {
A.date[0] = k;
int i;
for (i = n; A.date[i]!=k; i--);
return i; /* Not found return 0, find back subscript */
}
int Mindsearch (date&a,int k,int N) {
int right = N and left = 1;
int mind;
while (Left<=right) {
Mind = (left + right)/2;
if (a.date[mind] = = k)
return mind;
else if (A.date[mind] < K)
left = mind + 1;
Else
right = Mind-1;
}
return 0; /* Not found return 0*/
}
Sequential lookups and binary lookups