Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
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
Complete using Standard C programming. Implement a singly linked list that performs the following: Displays the maximum value in the linked list using recursion. Displays the linked list in reverse order using recursion. Merge two single linked lists and display.
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.
Write 2 recursive functions
1. to count number of even values in an
array
2. to count number of even values in a
simply linked list
Chapter 18 Solutions
Starting Out with C++: Early Objects
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. 13PC
Knowledge Booster
Similar questions
- Task:implement a function that reverses a list of elements by pushing them onto a stack in one order and writing them back to the list in reversed order P.S:Answer must be in pythonarrow_forward4. Sort elements in an array-based stack in ascending order, i.e. make the smallest element to be the top element of the stack. E.g. given the stack elements (from bottom to top): 90, 70, 80, 10, sort the elements to make the stack elements become (from bottom to top): 90, 80, 70, 10. The only data structure you can use is array-based stack. In addition to the given stack, you can use only one extra stack to store some temporary data. Given a stack st, use one extra stack, tmpst, to store temporary data. Here are some hints of the idea. Pop out the top element of st to a variable tmp. If the stack tmpst is empty, push tmp onto tmpst; if tmpst is not empty, pop out its top element and push that element onto st until the top element of tmpst is smaller than tmp, then push tmp onto tmpst .. a. Write a program to implement the stack based sorting. b. Take the input (90, 70, 80, 10) as an example. c. Print all the push and pop operations in proper format. d. At the end, print the sorted…arrow_forwardStack: push(x) adds x to top of stack pop() removes top element of stack and returns it size() returns number of elements in stack Select all options that allow for an efficient implementation based on the discussions from class. For any array implementation, you can assume the array is large enough so that making a larger one is not needed when pushing an item to the stack. Using an array with the top at the front of the array. Using an array with the top at the back of the array. Using a singly linked list with the top at the head of the list. Using a singly linked list with the top at the tail of the list. None of these choices allows for an efficient implementation of all methods.arrow_forward
- 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.)arrow_forwardJava Programming Hello! Can you make an algorithm / code for this part for my java calculator application. (see attached photo) All basic operations are already working, only the M's are needed to be implemented. Contains 'M+', 'M-', 'MC', 'MR' buttons(used to temporarily store data) with the corresponding stack functionalities as follows: 'M+' is push 'M-' is pop 'MC' is clear stack 'MR' is peakarrow_forwardConsider the Stack ADT: Stack: push(x) adds x to top of stack pop() removes top element of stack and returns it size() returns number of elements in stack Select all options that allow for an efficient implementation based on the discussions from class. For any array implementation, you can assume the array is large enough so that making a larger one is not needed when pushing an item to the stack. Using an array with the top at the front of the array. Using an array with the top at the back of the array. Using a singly linked list with the top at the head of the list. Using a singly linked list with the top at the tail of the list. ENGarrow_forward
- Pythonarrow_forwardPlease 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_forwardQuestion 5 Implement binary search algorithm recursively on a list using F# Full explain this question and text typing work only thanksarrow_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