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
in C++...
kth Element
Extend the class linkedListType by adding the following operations:a. Write a function that returns the info of the kth element of the linked list. If no such element exists, terminate the program.b. Write a function that deletes the kth element of the linked list. If no such element exists, terminate the program. Provide the definitions of these functions in the class linkedListType.
PLEASE DON'T reject this question, this is the whole question that I have... so please do it however u can, Thank you!
Add the following functions and write a program to test these functions in the class linkedListType: a. Write the definition of a function that returns the data of the kth element of the linked list. If such element is not exist in the list, exit the program. b. Write the definition of a function that deletes the kth element of the linked list. If such element is not exist in the list, exit the program and display message as output.
(Subject:Data stracture and algorithm )
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.
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
- in C++ kth ElementExtend the class linkedListType by adding the following operations:a. Write a function that returns the info of the kth element of the linked list. If no such element exists, terminate the program.b. Write a function that deletes the kth element of the linked list. If no such element exists, terminate the program. Provide the definitions of these functions in the class linkedListType. please, do not copy from any other sources, give me a fresh new code. Thank youarrow_forwardProvide me complete and correct solution thanks 3arrow_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_forward
- Using JavaScriptDefine a function getMonth which accepts number from 1 to 12 as an argument and return the descriptive name of the month. For example: getMonth(1) should return January while getMonth(12) returns December, finally getMonth(-1) returns null. Use array or object to define a list of names for the month and refrain from using if statement to check the argument if it's 1, 2, etc.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_forward2. Write a RACKET code and attach a Snapshot of your CODE herearrow_forward
- Need 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_forwardWrite 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_forward
- mergeAndRemove(int[], int[]) This is a public static function that takes a int[] and int[] for the parameters and returns an int[]. Given two arrays of integers. Your job is to combine them into a single array and remove any duplicates, finally return the merged array.arrow_forwardThis one in c++.arrow_forwardPlease write a full C++ code The function insert of the class orderedLinkedList does not check if the item to be inserted is already in the list; that is, it does not check for duplicates. Rewrite the definition of the function insert so that before inserting the item, it checks whether the item to be inserted is already in the list. If the item to be inserted is already in the list, the function outputs an appropriate error message. Also, write a program to test your function Also please allow the code to be copied. Don't just provide a screenshotarrow_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