Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
Question
Book Icon
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.

Blurred answer
Students 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.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning