Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 17, Problem 3P
Program Plan Intro
Recursive Binary Search
Program Plan:
- Include the required header files.
- Declare the global variables.
- Declare the function template.
- Define main function.
- Declare the required variables.
- Get the array of elements.
- Display the given display.
- Sort the array in ascending order.
- Display the sorted array.
- Call the “search” function with the arguments.
- If the “found” value is true, display the search element location. Otherwise display, “the element is not found”.
- Define the “search” function
- Declare the variable
- If “first” is greater than “last”, set “found” value as “false”.
- Otherwise find the “mid” value.
- If the “key” value is equal to “a [mid]”, set “found” value as “true” and also set “location” as “mid”.
- If the “key” is less than “a [mid]”, call the “search” function with the arguments.
- Otherwise, call the “search” function with the arguments.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
3. Write a class for the city database using unordered lists. Each database record contains the
name of the city (a string of arbitrary length) and the coordinates of the city expressed as
integer x and y coordinates. Your database should allow records to be inserted, deleted by
name, and searched by name or coordinate.
Implement the database using an array-based list.
Develop a simple test (as the main function)
Run your program and present the results of the test.
WITHOUT USING VECTOR ARRAY. Using c++ . Write different code rather than 2 codes that already existed in this question on this website.
Provide me complete and correct solution thanks 3
Chapter 17 Solutions
Problem Solving with C++ (10th Edition)
Ch. 17.1 - Write a function template named maximum. The...Ch. 17.1 - Prob. 2STECh. 17.1 - Define or characterize the template facility for...Ch. 17.1 - Prob. 4STECh. 17.1 - Display 7.10 shows a function called search, which...Ch. 17.1 - Prob. 6STECh. 17.2 - Give the definition for the member function...Ch. 17.2 - Give the definition for the constructor with zero...Ch. 17.2 - Give the definition of a template class called...Ch. 17.2 - Is the following true or false? Friends are used...
Ch. 17 - Write a function template for a function that has...Ch. 17 - Prob. 2PCh. 17 - Prob. 3PCh. 17 - Redo Programming Project 3 in Chapter 7, but this...Ch. 17 - Display 17.3 gives a template function for sorting...Ch. 17 - (This project requires that you know what a stack...Ch. 17 - Prob. 6PPCh. 17 - Prob. 7PPCh. 17 - This project requires that you complete...
Knowledge Booster
Similar questions
- Differences between void and NULL pointers are as follows: Provide relevant instances to back up your claim.arrow_forwardAdd the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function. I have 5 tabs: I have tried every solution I can think of with no luck. These are the guides: arrayListType.h arrayListTypeImp.cpp: main.cpp unorderedArraryListType.h unorderedArrayListTypeImp.cpp I am needing these in order to pass the assignment in Cengage Mindtap, please help with codes for each one if possible.arrow_forwardCan you help with with the following questions, regarding population genetics and the Wright Fisher model in python? 1. Go through the given WFtrajectory function and give a short explanation of what each line of code does. Pay attention to the variables in the function and explain what they contain. 2. Make a new version of the WFtrajectory function which does exactly the same thing except that instead of appending to a list it initialises a numpy vector with zeroes and fills the vector with a for loop instead of a while loop. Make a plot of the output from a few example trajectories.arrow_forward
- Write in c++arrow_forwardNeed help making a java file that combines both linearSearch and binarySearch •Both search methods must use the Comparable<T> interface and the compareTo() method.•Your program must be able to handle different data types, i.e., use generics.•For binarySearch, if you decide to use a midpoint computation formula that is different fromthe textbook, explain that formula briefly as a comment within your code. //code from textbook //linearSearch public static <T> boolean linearSearch(T[] data, int min, int max, T target) { int index = min; boolean found = false; while (!found && index <= max) { found = data [index].equals(target); index++; } return found; } //binarySearch public static <T extends Comparable<T>> boolean binarySearch(T[] data, int min, int max, T target) { boolean found = false; int midpoint = (min + max)/2; if (data[midpoint].compareTo(target)==0)…arrow_forwardThis in c++.arrow_forward
- Write a function, to be included in an unsorted linked list class, called replace_item, that will receive two parameters, one called olditem, the other called newitem. The function will replace all occurrences of olditem with newitem ( if olditem exists !! ) and it will return the number of replacements done.arrow_forwardThis one in c++.arrow_forwardI need the answer within 15 minutes.arrow_forward
- Write the full Java code for LabProgram.javaarrow_forwardImplements clone which duplicates a list. Pay attention, because if there are sublists, they must be duplicated as well. Understand the implementation of the following function, which recursively displays the ids of each node in a list Develop your solution as follows: First copy the nodes of the current list (self) Create a new list with the copied nodes Loop through the nodes of the new list checking the value field If this field is also a list (use isinstance as in the show_ids function) then it calls clone on that list and substitutes the value. Complete the code: def L4(*args,**kwargs): class L4_class(L): def clone(self): def clone_node(node): return <... YOUR CODE HERE ...> r = <... YOUR CODE HERE...> return r return L4_class(*args,**kwargs)arrow_forwardYou are tasked to implement an abstract data type class which takes in a given input file called input.txt, and processes, identifies and sorts all unique word instances found in the file. Sample Input Hi hello hi good bye goodbye Bye bye good say Sample Output Bye Hi bye hello hi say The input.txt file is found along with the zip folder where this instructions file also came along with. Note: you are not allowed to use pythonic lists, and its methods and functions, and string methods. However the use of the file handling methods (read readlines and readline) are allowed for this project.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning