Access over 35 million academic & study documents

4 (assessed) In class StackDemo, complete the method alternateItems

Content type
User Generated
Rating
Showing Page:
1/1
4. (assessed) In class StackDemo, complete the method
alternateItems that when passed a stack of integers,
returns a stack containing every alternate item, starting
from the top item, from the passed stack. For example, if
the stack passed is [6, 3, 1, 8] (where 8 is the top item),
returns the stack [3, 8], and when the stack passed is [2,
6, 3, 1, 8], returns the stack [2, 3, 8].
Solution
I\'ll give you a hint; create an empty out stack. If the in
stack is not empty, pop from the in stack (store as t), push
t to the out stack, pop from the in stack, repeat from if.

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
4. (assessed) In class StackDemo, complete the method alternateItems that when passed a stack of integers, returns a stack containing every alternate item, starting from the top item, from the passed stack. For example, if the stack passed is [6, 3, 1, 8] (where 8 is the top item), returns the stack ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Really helped me to better understand my coursework. Super recommended.

Studypool
4.7
Indeed
4.5
Sitejabber
4.4