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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education