Question: Hi, I need help with 2 tasks for Python, please. :) Write and test the following function that uses a Stack: def stack_split_alt(source): -------------------------------------------------------
Hi, I need help with 2 tasks for Python, please. :)
Write and test the following function that uses a Stack:
def stack_split_alt(source):
"""
-------------------------------------------------------
Splits the source stack into separate target stacks.
When finished source stack is empty. Values are
pushed alternately onto the returned target stacks.
Use: target1, target2 = stack_split_alt(source)
-------------------------------------------------------
Parameters:
source - the stack to split into two parts (Stack)
Returns:
target1 - contains alternating values from source (Stack)
target2 - contains other alternating values from source (Stack)
-------------------------------------------------------
"""
Add the function to a PyDev module named functions.py. Test it from t01.py.
The stack_split_alt function uses a Stack, meaning you may manipulate the Stack using only the Stack interface methods such as push, pop, isEmpty, and peek. You may not use or refer to the internal Stack properties such as _values.
Sample result (values are listed top to bottom):

Write and test the following that uses a stack:
def stack_combine(source1, source2):
"""
-------------------------------------------------------
Combines two given Stacks into a target stack.
When finished, the contents of source1 and source2 are interlaced
into target and source1 and source2 are empty.
Use: target = stack_combine(source1, source2)
-------------------------------------------------------
Parameters:
source1 - a stack (Stack)
source2 - another stack (Stack)
Returns:
target - the contents of the source1 and source2
are interlaced into target (Stack)
-------------------------------------------------------
"""
Add the function to a PyDev module named functions.py. Test it from t03.py.
This function uses a stack, meaning you may manipulate the stack using only the stack interface methods: push, pop, isEmpty, and peek. You may not use or refer to the internal Stack attributes such as _values.
Sample result (values are listed top to bottom):

Thank you!
sour targe targe t1 t2 8 14 12 9 8 7 5 5 8 12 8 7 9 14 sourc e 1 sourc e2 targ et 5 8 12 8 3 6 1 7 9 14 14 9 7 8 1 12 6 8 3 5 sour targe targe t1 t2 8 14 12 9 8 7 5 5 8 12 8 7 9 14 sourc e 1 sourc e2 targ et 5 8 12 8 3 6 1 7 9 14 14 9 7 8 1 12 6 8 3 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
