Monday, April 16, 2012

STL algorithm function templates

The program has to finds an element in a sorted array and implement this function template:



bool find(T *p, T value, int &index=null)


I have completed a part, but when I try to do the Null part all my number goes to zeros. Also I do not know how to implement the index. Can someone help me please.



int main()
{
vector<int> numbers;
vector<int>::iterator iter;

for (int x = 0; x < 15; x++)
numbers.push_back(x);

cout << "The numbers in the vector are:\n";
for (iter = numbers.begin(); iter != numbers.end(); iter++)
cout << *iter << " ";
cout << endl << endl;

iter = find(numbers.begin(), numbers.end(), 5);
cout << *iter << endl;




No comments:

Post a Comment