Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a typical Queue q with elements [E,D,C,B,A] (where Front/left of at E and Rear/right of Queue at A), determine and list elements of the

Given a typical Queue q with elements [E,D,C,B,A] (where Front/left of at E and Rear/right of Queue at A), determine and list elements of the updated Queue in the similar form (Front/left and Rear/right), after the following execution: q.enqueue( q.dequeue () ) q.enqueue G ) q.dequeue() [2 marks] 5/6 b) Given a typical Stack s with elements [T,W,X,Y,Z] (where Top/left of Stack at T) and a typical Queue q with elements [E,D,C,B,A) (where Front/left of Queue at E and Rear/right of Queue at A), determine and list elements of the updated Stack and those of the updated Queue in their similar forms after the following execution: q.enqueue( s.pop() ) s.push( R ) q.enqueue( s.peek() ) s.push( q. dequeue() ) q.enqueue( s.pop() ) (4 marks] COPACE c) Given a Python Queue class implemented with the abstract data type (ADT) below, write a new method popqueue(), which will pop\" (remove and return) the last-in element from the rear end of the queue. Operation (Queue) Description sizeQ(): int GIVEN: Get (and return) the size of the queue (total number of elements) enqueue (elt): GIVEN: Insert elt into Queue dequeue():elt GIVEN: Remove and return) element from Queue popqueue():elt Remove and return) the last-in element from rear end of Queue c) Given a Python Queue class implemented with the abstract data type (ADT) below, write a new method popqueue (), which will \"pop\" (remove and return) the last-in element from the rear end of the queue. Operation (Queue) Description sizeQ(): int GIVEN: Get (and return) the size of the queue (total number of elements) enqueue (elt): GIVEN: Insert elt into Queue dequeue():elt GIVEN: Remove and return) element from Queue popqueue():elt Remove (and return) the last-in element from rear end of Queue Finish this new Python popqueue() method, by completing the method body below: def popqueue self ): # remove and return rear elt # body of the method. TO BE COMPLETED by student o No other extra variable could be added including Python's list, except int and range with function range(). No more than 4 lines of typical python code (without semicolon symbol ;) allowed in the method body. * Hint: you may finish this task using its own given methods of the Queue class, and a for loop with function range(). [4 marks) muni Lahe Queen oallom




Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

1 Apply the three-step writing process to persuasive messages

Answered: 1 week ago