STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 12PC
Program Plan Intro
Stack Based Binary Search
Program Plan:
- Create a class Range.
- Include required header files.
- Declare two integers lower and upper to set the lower and upper level for comparison.
- Set the range for comparison.
- Create a method binary search that searches for an element within two levels where the element array, size of array and the number to search is passed as a parameter.
- Create the main function.
- Define and create a random array having 10 elements.
- Define the array size.
- Prompt the user to ask for a value to search within array.
- Call the binary search method and return the position of the value if it is present in the array.
- Define and create a random array having 10 elements.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Show a complete run of Quicksort on the following array X :X: 1 2 3 4 5 6 7 8 9 1017 5 -3 40 46 50 16 0 22 4
show all recursive calls using the stack below. Show the results of each call to below Split on a newline in the table to the left.
A drop-out stack is a data structure that acts just like a stack except that if the stack size is n, and the n + 1 element is pushed, the first element is lost. Using an array, create a drop-out stack. (Hint: A circular array implementation would be appropriate.)
Stack stores elements in an ordered list and allows insertions and deletions at one end.
The elements in this stack are stored in an array. If the array is full, the bottom item is dropped from the stack. In practice, this would be equivalent to overwriting that entry in the array. And if top method is called then it should return the element that was entered recently.
Chapter 18 Solutions
STARTING OUT WITH C++ MPL
Ch. 18.3 - Describe what LIFO means.Ch. 18.3 - What is the difference between static and dynamic...Ch. 18.3 - What are the two primary stack operations?...Ch. 18.3 - What STL types does the STL stack container adapt?Ch. 18 - Prob. 1RQECh. 18 - Prob. 2RQECh. 18 - What is the difference between a static stack and...Ch. 18 - Prob. 4RQECh. 18 - The STL stack is considered a container adapter....Ch. 18 - What types may the STL stack be based on? By...
Ch. 18 - Prob. 7RQECh. 18 - Prob. 8RQECh. 18 - Prob. 9RQECh. 18 - Prob. 10RQECh. 18 - Prob. 11RQECh. 18 - Prob. 12RQECh. 18 - Prob. 13RQECh. 18 - Prob. 14RQECh. 18 - Prob. 15RQECh. 18 - Prob. 16RQECh. 18 - Prob. 17RQECh. 18 - Prob. 18RQECh. 18 - Prob. 1PCCh. 18 - Prob. 2PCCh. 18 - Prob. 3PCCh. 18 - Prob. 4PCCh. 18 - Prob. 5PCCh. 18 - Prob. 6PCCh. 18 - Prob. 7PCCh. 18 - Prob. 8PCCh. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 14PCCh. 18 - Prob. 15PC
Knowledge Booster
Similar questions
- A tail recursion is a type of recursion in which the access of the tail pointer of a linked list is recursive a) true b)falsearrow_forwardQuestion 1a: Write an algorithm / program that accept ten values and store them in an array in sorted order. 1B: Write a program that implements stack and queue by using array and link list.arrow_forwardHaskarrow_forward
- Please solve this problem in Java. It should read the elements of the stack as integers from a text file. n = 18 (number of elements/integers)arrow_forwardShow the call stack for sort([2, 3, 5, 1]) using the function defined inListing 15.5. LISTING 15.5 RecursiveSelectionSort.py1 def sort(lst):2 # Sort the entire list345 if low < high:6 # Find the smallest element and its index in lst[low .. high]7 indexOfMin = low 8 min = lst[low]9 for i in range(low + 1, high + 1):10 if lst[i] < min:11 min = lst[i]12 indexOfMin = i1314 # Swap the smallest in lst[low .. high] with lst[low]15 lst[indexOfMin] = lst[low]16 lst[low] = min1718 # Sort the remaining lst[low+1 .. high]192021 def main():22 lst = [3, 2, 1, 5, 9, 0]23 sort(lst)24 print(lst)2526 main() # Call the main functionarrow_forwardRecursive Multiplication Given an JavaScript object list of books that each have a pages attribute to define the number of pages in the book, find the product of all the pages in the object list of books using recursion (you must use recursion to solve this problem). Keep in mind: The input list object may be completely empty (ex. {}) The next attribute may not be defined function getPageCount(list) {// your code here// returns an integer}Example test case:Input: {"book":"A","pages":1,"next":{"book":"B","pages":2,"next":{"book":"C","pages":3,"next": null}}}Output: 6Reasoning: 1 * 2 * 3 pagesarrow_forward
- Question 1:Convert a decimal to binary and binary to decimal using recursionTest your implementation with following examples:● (1947)10 = (11110011011)2● (1992)10 = (11111001000)2● (2021)10 = (11111100101)2Question 2:Implement a member function that prints a singly linked list in reverse order without creating acopy or changing the original List.void printBackwards() constQuestion 3:Implement a recursive member function “isSorted” which recursively checks whether the linked listis sorted (ascendingly).bool isSorted() constQuestion 4:You will implement a function bool Equalize_Occurrences (char key, int maxcount) of theclass list, that will take a character key and maximum count for the consecutive occurrences of thekey inparameters. It will then traverse the list, verify and update the consecutive occurrences of the keyaccordingto maximum count and returns true. It returns false if no occurrence of key is found.Note: You can traverse the list only once for this task.arrow_forwardIn JAVA Recursive Array Search. Define and test a recursive method for a sequential search of an integer array. The method should return the index of the searchKey in the array, or return -1 if the searchKey is not found.arrow_forwardplz do not copy from chegg Problem 1. Implement a sorted singly linked list and support the following operations: bool SortedIsEmpty(): return true if the list is empty; int SortedGetLength(): return the length of the list; bool SortedFind(int k, int& x): return the value of the kth element; int SortedSearch(int key): return the position of the element which is same as key (note: use the most efficient method); void SortedInsert(int x): insert x to the right position in the sorted linked list; void SortedDelete(int k, int& x, bool& success): delete the kth element. Part (1) Implement the aboved singly linked list allowing the duplicate element. Part (2) Implement the above singly linked list without allowing the duplicate element. Test your program for both parts with the following operations: Insert 5 Insert 7 Insert 9 Insert 11 Insert 5 Print out the list Insert 7 Print out the list Find the 3rd element Search 7 Print out the length of the list Delete 7 Print out the…arrow_forward
- solve this task using pythonarrow_forwardPlease solve thisarrow_forwardjava quick sort use the skeleton code to do task below skeleton code 1 class QuicksortTester2 {34 /**5 * Quicksort algorithm (driver)6 */78 public void quicksort( int [ ] a )9 {10 quicksort( a, 0, a.length - 1 );11 }1213 /**14 * Internal quicksort method that makes recursive calls.15 * Uses median-of-three partitioning and a cut-off.16 */1718 public void quicksort( int [ ] a, int low, int high )19 {20 if( low + CUTOFF > high )21 insertionSort( a );22 else23 { // Sort low, middle, high24 int middle = ( low + high ) / 2;25 if( a[ middle ].compareTo( a[ low ] ) < 0 )26 swapReferences( a, low, middle );27 if( a[ high ].compareTo( a[ low ] ) < 0 )28 swapReferences( a, low, high );29 if( a[ high ].compareTo( a[ middle ] ) < 0 )30 swapReferences( a, middle, high );3132 // Place pivot at position high - 133 swapReferences( a, middle, high - 1 );34 int pivot = a[ high - 1 ];3536 // Begin partitioning37 int i, j;38 for( i = low, j = high - 1; ; )39 {40 while( a[ ++i ].compareTo(…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