Question: Directed Lab Work Stack Sort Pieces of the StackSort class already exist and are in StackSort.java . Take a look at that code now if
Directed Lab Work
Stack Sort
Pieces of the StackSort class already exist and are in StackSort.java Take a look at that code now if you
have not done so already. Also before you start, make sure you are familiar with the methods available to you
in the VectorStack class check StackInterface.html
Step Compile the classes StackSort and VectorStack Run the main method in StackSort
Checkpoint: If all has gone well, the program will run. It will create arrays of various sizes and print out the
result of StackSort method. At the end, the program will ask you to enter an integer value. It will use the
value to create and then sort an array of that size. Enter any value. The sorted arrays as reported by the
program should all be empty. Our first goal is to get values into a stack and then move them to the result array.
Step Create a new VectorStack and assign it to lowerValues
Step Create a new VectorStack and assign it to upperValues
Step Using a loop, scan over the values in the argument array data and push them onto the
upperValues stack.
Step Using a loop, pop all the values from the upperValues stack and place them into the array
result
Checkpoint: Compile and run the program. Again it should run and ask for a size. Any value will do This
time, you should see results for each of the calls to the StackSort method. The order that values are popped off
the stack should be in the reverse order that they were put on the stack. If all has gone well, you should see the
values in reverse order in the results array. We will now complete the StackSort method
Step Inside the loop that scans over the data array, we need to move the data between the two stacks
before we push the value. Refer to the prelab exercise to complete the body of the loop.
Step Before the loop that pops the data values from the upperValues stack, we need to move any data
values from the lowerValues stack. Refer to the prelab exercise to implement this loop.
Checkpoint: Compile and run the program. The output of the StackSort method should be the original arrays in
sorted order. If not, debug until the results are correct.
Lab Manual for Data Structures and Abstractions with Java
PostLab FollowUps
It should not matter into which stack the values from the data array are pushed. Change the stack that
your implementation pushes the values and verify that the output is still correct.
Write a program that determines if an input string is a valid equation in unary representation with
addition. For example:
a is the statement that and is valid.
b is not valid because is not equal to
c is not valid because we only allow one equal sign
d is not valid because we only allow the characters and
You have one small restriction. You are not allowed to use the built in arithmetic of the computer, but
instead are only allowed to match characters. Furthermore, you are only allowed to scan over
characters once. This can be done with a single stack. The general idea is to scan over the string and
push s until you see the After that match the s by poping values off of the stack. You can
decide validity by tracking if the stack is empty. If the stack empties and there are still s in the
input, it is not valid. If the input has all been used, but the stack is not empty, it is not valid.
Write a program that solves the previous problem extended to allow multiple occurences of For
example, is a valid equation. To do this you will need three stacks. One
stack is a long term memory, one stack is working memory, and the final stack allows duplication.
Push s on the long term stack until you get an Each time you read an equal, you will pop each
off of the long term stack and push a on both of the other two stacks. Once this is done, pop all
the s off of the duplicate stack and push them back onto the long term memory stack. Match the
s in the input with the working memory stack.
Write a program that will determine if an input string is a palindrome. A palindrome is a string that
reads the same forwards and backwards. For example, Madam Im Adam. and Able I was ere I
saw Elba. are two classic palidromes. A stack is a natural structure for allowing us to determine if a
string is a palindrome since characters come off the the stack in the reverse order that they are pushed
onto the stack. Take each alpha character in the string ignore punctuation and spaces converted to
lower case and push it on two different stacks called reversed and temporary Pop each of the
characters off of the temporary stack and push them on a third stack called ori
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
