Question: And this is my process Write a recursive function template whose prototype is given by template 2 const T *binarySearch(const T*first, const T last, T

 And this is my process Write a recursive function template whoseprototype is given by template 2 const T *binarySearch(const T*first, const Tlast, T itemToFind); The function performs a binary search of the range

And this is my process

[first, last] for itemToFind. The function returns an address i in the

Write a recursive function template whose prototype is given by template 2 const T *binarySearch(const T*first, const T last, T itemToFind); The function performs a binary search of the range [first, last] for itemToFind. The function returns an address i in the range [first, last] such that iitemToFind. The function returns nullptr if no such address exists. A main function for testing your function is shown in Figure 1. The expected output from executing this code is shown in Figure 2. To use the Makefile as distributed in class, add a target of lab22main to targetsiarcfile #include #include using namespace std e /I function template prototype 7 templatectypename T> s conat T *binarySearch(conat T first, const T last, T itemToFind); 10 #include "lab22.cpp 12 templatectypename T> ia void printArray (conat T array, int count) isif (count > 0) cout as void printAndSearch(const T array, int n, T itemToFind, string nameOf Array) a const T ptr; 2 cout ("Cadillac"), "d") 5 printAndSearch(d, dCount, atatic_caatcatring>("Mercedes"), "d"); return 0; 60 Figure 1. /usr/local/2336 /src/lab2hain. (Part 2 of 2) 1 newuser csunix> cd 2336 2 newuser@csunix /2336> ./getlab.ksh 22 * Checking to see if a folder exists for Lab 22. . . No Creating a folder for Lab 22 Checking to see if Lab 22 has sample input and output files. . .Yes 6Copying input and output files for Lab 22 5 from folder /usr/local/2336/data/22 to folder ./22 Checking to see if /usr/local/2336/src/lab22main.C exists. . .Yes * Copying file /usr/local/2336/src/lab22main . to folder . /22 Checking to see if /usr/local/2336/include/1ab22.h exists...No Copying file /usr/local/2336/src/Makefile to folder /22 12Adding a target of lab22main to targets1srcfile * Touching file . /22/1ab22. cpp Edit file /22/1ab22.cpp in Notepad++ s newuser@csunix /2336> cd 22 16 newuser@csunix /2336/22> 1s 1 01.out s newuser@csunix /2336/22> make lab22main i g++ -g -Wall-std-c++11 lab22main.C -I/usr/local/2336/include I 20 gt+ -o lab22main lab22main.o -L/usr/local/2336/lib -1m -1bits lab22 . cpp lab22main.c 1 21 newuser@csunix /2336/22 ./lab22main 22Array a contains: 2 5 15 25 35 45 24 25 is in array a and is located at index 2 26 Array a contains: 27 5 15 25 35 45 55 is not in array a 30 Array b contains: a 1.1 2.2 3.3 4.4 5.5 6.6 7.7 a2 1.1 is in array b and is located at index 0 Array b contains: as 1.1 2.2 3.3 4.4 5.5 6.6 7.7 611.11 is not in array b Array c contains: 39 ab cdef ghijkl m n o pqrstuv x y z z is in array c and is located at index 25 42 Array c contains: abcdef g hijkl m n o p q rst uvwx y z " Z is not in array c 46 Array d contains: Audi BMW Bentley Buick Cadillac Chevrolet Dodge GMC Jaguar Lexus 4s Cadillac is in array d and is located at index 4 Array d contains: s Audi BMW Bentley Buick Cadillac Chevrolet Dodge GMC Jaguar Lexus 2 Mercedes is not in array d newuser@csunix /2336/22> ./lab22main > my.out 5 nevuser@csunix /2336/22> diff 01.out my.out s6 newuser@csunix /2336/22> #include #include using namespace std; //function template prototype template const T *binarySearch (const T*first, const T last, T itemToFind) int middle: bool found-false; while (first1: if (itemToFind -first [middle]) return &first [middle] : else BinarySearch (middle, last, itemToFind) return NULL Write a recursive function template whose prototype is given by template 2 const T *binarySearch(const T*first, const T last, T itemToFind); The function performs a binary search of the range [first, last] for itemToFind. The function returns an address i in the range [first, last] such that iitemToFind. The function returns nullptr if no such address exists. A main function for testing your function is shown in Figure 1. The expected output from executing this code is shown in Figure 2. To use the Makefile as distributed in class, add a target of lab22main to targetsiarcfile #include #include using namespace std e /I function template prototype 7 templatectypename T> s conat T *binarySearch(conat T first, const T last, T itemToFind); 10 #include "lab22.cpp 12 templatectypename T> ia void printArray (conat T array, int count) isif (count > 0) cout as void printAndSearch(const T array, int n, T itemToFind, string nameOf Array) a const T ptr; 2 cout ("Cadillac"), "d") 5 printAndSearch(d, dCount, atatic_caatcatring>("Mercedes"), "d"); return 0; 60 Figure 1. /usr/local/2336 /src/lab2hain. (Part 2 of 2) 1 newuser csunix> cd 2336 2 newuser@csunix /2336> ./getlab.ksh 22 * Checking to see if a folder exists for Lab 22. . . No Creating a folder for Lab 22 Checking to see if Lab 22 has sample input and output files. . .Yes 6Copying input and output files for Lab 22 5 from folder /usr/local/2336/data/22 to folder ./22 Checking to see if /usr/local/2336/src/lab22main.C exists. . .Yes * Copying file /usr/local/2336/src/lab22main . to folder . /22 Checking to see if /usr/local/2336/include/1ab22.h exists...No Copying file /usr/local/2336/src/Makefile to folder /22 12Adding a target of lab22main to targets1srcfile * Touching file . /22/1ab22. cpp Edit file /22/1ab22.cpp in Notepad++ s newuser@csunix /2336> cd 22 16 newuser@csunix /2336/22> 1s 1 01.out s newuser@csunix /2336/22> make lab22main i g++ -g -Wall-std-c++11 lab22main.C -I/usr/local/2336/include I 20 gt+ -o lab22main lab22main.o -L/usr/local/2336/lib -1m -1bits lab22 . cpp lab22main.c 1 21 newuser@csunix /2336/22 ./lab22main 22Array a contains: 2 5 15 25 35 45 24 25 is in array a and is located at index 2 26 Array a contains: 27 5 15 25 35 45 55 is not in array a 30 Array b contains: a 1.1 2.2 3.3 4.4 5.5 6.6 7.7 a2 1.1 is in array b and is located at index 0 Array b contains: as 1.1 2.2 3.3 4.4 5.5 6.6 7.7 611.11 is not in array b Array c contains: 39 ab cdef ghijkl m n o pqrstuv x y z z is in array c and is located at index 25 42 Array c contains: abcdef g hijkl m n o p q rst uvwx y z " Z is not in array c 46 Array d contains: Audi BMW Bentley Buick Cadillac Chevrolet Dodge GMC Jaguar Lexus 4s Cadillac is in array d and is located at index 4 Array d contains: s Audi BMW Bentley Buick Cadillac Chevrolet Dodge GMC Jaguar Lexus 2 Mercedes is not in array d newuser@csunix /2336/22> ./lab22main > my.out 5 nevuser@csunix /2336/22> diff 01.out my.out s6 newuser@csunix /2336/22> #include #include using namespace std; //function template prototype template const T *binarySearch (const T*first, const T last, T itemToFind) int middle: bool found-false; while (first1: if (itemToFind -first [middle]) return &first [middle] : else BinarySearch (middle, last, itemToFind) return NULL

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!