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.
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.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps