Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python Write a function reverse in python that takes a queue as a parameter and returns a new queue in reverse order. Your solution should
python
Write a function reverse in python that takes a queue as a parameter and returns a new queue in reverse order. Your solution should not use any built-in or library functions other than those in the Stack and Queue classes provided.
fix reverse.py to pass reverse_test.py
LI reverse.py 1 from Queue import Queue from Stack import Stack 3 N 3 4 5 6 LO 7 # Return a new queue in reverse order # Hint: can use a stack to help def reverse(q_orig): q_new = Queue ([]) return q_new 00 9 10 11 12 13 def main(): q = Queue (list(range(1, 5))) q.print() print("reverse: ", end="") reverse(q).print() 14 15 16 17 18 # Don't run main on import if _name _main__": main() 19 LI N 00 reverse_test.py 1 # TEST FILE FOR REVERSE # DO NOT MODIFY 3 4 from Queue import Queue 5 from reverse import reverse 6 7 def test_reverse_4(): 8 assert reverse(Queue (list(range(1, 5)))) == Queue ( [4, 3, 2, 1]) 9 10 def test_reverse_0(): 11 assert reverse(Queue ([])) == Queue ([]) 12 13 def test_reverse_1(): 14 || assert reverse(Queue ([@])) == Queue ([0]) 15 16 def test_reverse_str(): 17 assert reverse(Queue ([1 for 1 in "hello"])) == Queue ([1 for 1 in "olleh"]) 18 19 def test_reverse_many(): 20 assert reverse(Queue (list(range(0, 101,5)))) == Queue (list(range(100,-1,-5))) 21 22 def test_reverse_neg(): 23 assert reverse(Queue (list(range(1,-10, -1)))) == Queue (list (range(-9, 2))) 24 2 4 L LI reverse.py 1 from Queue import Queue from Stack import Stack 3 N 3 4 5 6 LO 7 # Return a new queue in reverse order # Hint: can use a stack to help def reverse(q_orig): q_new = Queue ([]) return q_new 00 9 10 11 12 13 def main(): q = Queue (list(range(1, 5))) q.print() print("reverse: ", end="") reverse(q).print() 14 15 16 17 18 # Don't run main on import if _name _main__": main() 19 LI N 00 reverse_test.py 1 # TEST FILE FOR REVERSE # DO NOT MODIFY 3 4 from Queue import Queue 5 from reverse import reverse 6 7 def test_reverse_4(): 8 assert reverse(Queue (list(range(1, 5)))) == Queue ( [4, 3, 2, 1]) 9 10 def test_reverse_0(): 11 assert reverse(Queue ([])) == Queue ([]) 12 13 def test_reverse_1(): 14 || assert reverse(Queue ([@])) == Queue ([0]) 15 16 def test_reverse_str(): 17 assert reverse(Queue ([1 for 1 in "hello"])) == Queue ([1 for 1 in "olleh"]) 18 19 def test_reverse_many(): 20 assert reverse(Queue (list(range(0, 101,5)))) == Queue (list(range(100,-1,-5))) 21 22 def test_reverse_neg(): 23 assert reverse(Queue (list(range(1,-10, -1)))) == Queue (list (range(-9, 2))) 24 2 4 LStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started