代码如下:
#include<iostream>
using namespace std;
#define maxSize 100
typedef struct Sqlist
{
int data[maxSize];
int length;
}Sqlist;
int main()
{
Sqlist a;
int e,t,s;
int getElement(Sqlist, int&,int);
cout << "Please enter the length of the linear list: " << endl;
cin >> a.length;
cout<<"Please enter "<<a.length<<" numbers as element of the list:" << endl;
for (int i = 0; i < a.length; i++)
{
cin >> a.data[i];
}
cout << "Please enter the index of the element which you wish to found:" << endl;
cin >> t;
s=getElement(a, e, t);
if (s)
{
cout << "The element you wish to found is: " << e << endl;
}
else
{
cout << "Error! Index out of range!" << endl;
}
return 0;
}
int getElement(Sqlist L, int& e, int t)
{
if (t < 0 || t >= L.length)
return 0;
e = L.data[t];
return 1;
}