#include<iostream>
using namespace std;
const int MaxSize = 100;
class LineSearch
{
public:
LineSearch(int a[], int n);
int SeqSearch(int k);
int BinSearch(int k);
private:
int data[MaxSize];
int length;
};
LineSearch::LineSearch(int a[], int n)
{
for (int i = 0; i < n; i++)
{
data[i + 1] = a[i];
}length = n;
}
int LineSearch::SeqSearch(int k)
{
data[0] = k;
int i = length;
while (data[i] != k)
{
i--;
}return i;
}int LineSearch::BinSearch(int k)
{
int low = 1, high = length;
while (low <= high)
{
int mid = (low + high) / 2;
if (data[mid] < k)
{
low = mid + 1;
}
else if (data[mid] > k)
{
high = mid - 1;
}
else
{
return mid;
}
}return 0;
}
int main()
{
int a[5] = { 1,2,3,4,5 };
LineSearch s(a, 5);
cout<<s.SeqSearch(4)<<endl;
cout << s.BinSearch(2) << endl;
}