You can start your homework with this skeleton program that the method headers for exercises 1-3 plus a main method that asks the user to enter a test stack, copies the stack and then tests all 3 methods.
This homework involves puzzle solving with only the given stack and queue structures allowed. You will be practicing these concepts:
When you cycle through a stack or queue, you are removing elements as you go.
Elements come off a stack in reverse order, so when you copy from a stack to
a new stack or queue, it will have the reverse order.
Queues do not reverse order when you copy from a queue to stack or queue.
To copy a stack to the same order, either put it into one stack and again into
another stack OR copy it to a queue and then to a stack and repeat again to
a queue and then to a stack. (This reverses the order twice, giving the original
order.)
When you are cycling through a queue removing some items, don't use q.size()
as the loop control, as the size will vary throughout the loop.
When you want to retrieve a value from a queue or stack and then put it in 2
places, put the value into a variable first instead of directly placiing on
the other structure.
Enjoy these puzzles.
Here is the starter code you can just copy into bluej. It will make your testing easier:
http://home.adelphi.edu/~pe16132/csc172/note/chap14HwkSkeleton.java