C++ visual studio 2015

Abdull2004
02_assign_stack_sort.pdf

Stack Sort

Goal In this lab you will complete an application that uses the Abstract Data Type (ADT) stack.

Resources  Chapter 4: Stacks

Introduction In computer science, one of the important basic structures is the stack. It is of both theoretical and practical use. In its simplest

form a stack has four operations:

 Push o Places a value on the top of the stack.

 Pop o Removes the top value from the stack.

 Empty o Determine if the stack has any values in it.

 Top o Returns the top value on the stack but leaves the top value in the stack. Peek can be emulated by a pop followed by

a push will mimic its operation.

Before continuing the lab you should review the material in Chapter 4.

The application you will complete implements a sorting a stack using another helper stack.

The stack should when sorted will have entries from the stack top to the stack bottom in ascending order (highest to lowest).

The stack sort in this lab is of O(𝑛2).

Pre-Lab Visualization

Stack Sort In order to sort values, use a source stack and a second helper stack that will have the sorted stack when the algorithm is done.

See the end of this document for a recommended solution.

Directed Lab Work Read the tutorial File IO Read Correctly that is posted on Canvas.

The program should read in a file named stackLoader.txt that should have lines of space separated text integers, where each

line of integers is to be loaded into a source stack.

See the recommended solution at the end of this document to learn how to read in a line of integers.

The program must:

 Be modular and well structured

 Have a function that reads a line of integers to be put into a stack and indicates when there is not any more data

 Display the read in stack, using one function that displays the stack

 A function that sorts the stack using only another helper stack and stack operations

 Display the sorted stack, using one function that displays the stack

 Loop around and repeat the processing o End the program when there is not any more data to be read in

Stack Sort

Stack Sort