Write a program that will sort a set of numbers. The program will use two array-based stacks. The stack that is being used at a given instant is called the working stack. When a new number is read, the non-working stack will be empty. One of the stacks will be arranged with the smallest element of the stack on the bottom, the other with the smallest element at the top. To process a number, test it against the top element of the "current" working stack. If it fits there, push it. If it does not fit, pop the top element of the working stack, push it on to the other stack, and continue testing. When the number "fits", push it on the other stack and empty the working stack onto the other stack. When the working stack is empty, the other stack becomes the new working stack.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

I can not use any of the stack libraries, i have to create the operators using arrays. 

The code must be written using c++

Write a program that will sort a set of numbers. The program will use two array-based stacks. The stack that is being used at a given instant is called the working stack. When a new number is read, the non-working stack will be empty. One of the stacks will be arranged with the smallest element of the stack on the bottom, the other with the smallest element at the top. To process a number, test it against the top element of the "current" working stack. If it fits there, push it. If it does not fit, pop the top element of the working stack, push it on to the other stack, and continue testing. When the number "fits", push it on the other stack and empty the working stack onto the other stack. When the working stack is empty, the other stack becomes the new working stack. Use the stack definitions and functions discussed in class. Do not manipulate the stacks except by calling the stack functions. Your main function should contain mostly function calls. Do not duplicate logic. Follow all good programming techniques. INPUT: 1. Assume that each stack holds at most 40 values. 2. Fill in your own data file containing at least 30 non-sorted integers. 3. Your program should be able to handle any data file of integers. OUTPUT: 1. Print the contents of the working stack after each number is added. 2. Print the sorted values in ascending and descending order. NOTE: All output should have appropriate headers and be completely formatted.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning