C++ question What would be the result of the following code fragment? (i.e. What
ID: 3860210 • Letter: C
Question
C++ question
What would be the result of the following code fragment? (i.e. What is stored in the variable where?) typedef vector :: size_type VLPos: VLPos locate(const vector & list, long find_me): .some_function(...) {vector heights: VLPos where: //fill heights with: 15, 14, 17, 18, 17, 13, 15, 16 where = locate(heights. 17): return...;} VLPos locate(const vector & list, long find_me) {VLPos k = 0: while ((k != list.size()) && (list[k] != find_me)) {k++;} return k;} What kind of search is this? Why is k being incremented? What is returned when find_me is not located within the list?Explanation / Answer
Here the output will be the location of the number in the given list.
Where contains the position of the number in the list
1) This performs the linear search
2) k is incremented to find the element in the list. the list is checked one by one.
3)if find me does not present then the while loop does not end
there willl not be any return value.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.