find
Apr 2, 2016 at 5:21pm UTC
int* find(int* first, int* limit, int value);
Returns: Returns a pointer to the first object in [first, limit) whose value is equal to value. Returns limit if no such object is found.
I'm not really sure what to do.. This is what I have.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <iostream>
using namespace std;
int * find(int * first, int * limit, int value){
if ()
*value = (first * limit);
std::cout << value << std::endl;
}
}
void print(int * first, int * limit){
while (first != limit){
std::cout << *first << ' ' ;
++first;
}
}
int main(){
int a[] = {1, 2, 3,4,5};
int * first = a; // Points to the first object in a
int * limit = a + 5;
print(a, a + 5);
}
Apr 2, 2016 at 6:58pm UTC
You'll want to do something similar to print(); iterate over the range provided, but instead of printing the values out increment a counter and return that if you find what you are looking for.
Topic archived. No new replies allowed.