Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ Return Target Iterator Goal of the code: You will need to traverse a vector using iterators. The task is to find a specific number

c++ Return Target Iterator

Goal of the code: You will need to traverse a vector using iterators. The task is to find a specific number that is guaranteed to be in the vector. Once you find the target number, return the iterator that points to that number. Starting from the returned iterator, print out the rest of the contents of the vector. Input: The first number is the target number you are going to search for. The rest of the input consists of space separated integers. Output: Print out the contents of the vector starting from the returned iterator with a space between each element. End the output on a new line.

Complete (fill in the blanks) and follow the instructions shown below in order to do the code.

Note:You are NOT allow to use namespace std;

#include #include

std::vector::iterator findIterator( std::vector & vec, int target ){ // Type your code here to find the target number iterator // The number will be in the vector, so use iterators to traverse the vector. When you find the target number, return the iterator. // You can see the value an iterator points to by using a dereference operator. }

int main(){ // Read in the first integer and save it to a variable. // Read in the rest of the integers into a vector. // Call the findIterator function, save the result to a variable. // Start from the returned iterator and print the contents of the vector. std::cout << std::endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

4. Devise an interview strategy from the interviewers point of view

Answered: 1 week ago