Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Write and test the following function that uses a Queue: def queue_split_alt(source): 1 2 IR IN c 2 1 o a 9 10 11

image text in transcribedimage text in transcribed

2. Write and test the following function that uses a Queue: def queue_split_alt(source): 1 2 IR IN c 2 1 o a 9 10 11 12 Splits the source queue into separate target queues with values alternating into the targets. At finish source queue is empty. Order of source values is preserved. (iterative algorithm) Use: target, targetz = queue_split_alt(source) Parameters: source - a queue (Queue) Returns: target1 - contains alternating values from source Queue) targetz contains other alternating values from source (Queue) 14 15 16 Add the function to a PyDev modulo named functions.py. Test it from t02.py This function uses a queue, meaning you may manipulate the queue using only the queue interface methods: insert, remove, is_empty, and peek. You may not use or refer to the internal Queue elements such as _values The Queue ADT The Que ADT represents a First-In-First-Out (FIFO, structure. Any waiting libe such as the check-out linc at a store, the cars at a stop light or the line-up outside a department store is a Queue. Figure 2 below shows the conxptual vicw of a QuCUC ADT. Queue has two propitics Damed front and rear. When a value is added to the Queue, it will be placed at the rear end) of the Qacue (think of a person joining a line, takes a place at the end of the linc). Whcoa value is removed from it Quelle, it is the value at the front of the Quelle (Think of the person at the front of the line wha has waited the longest). The Queue ADT implements First-In-First-Out (FIFO) hehaviour hecause the value removed is the one that has heen in the Queue Ir the Ingest time. A Simple Queue remove front rear insert 1 Queue Methods and Properties 1.1 The basic queue properties are: reur: keep track of the last value added to the Queue Fron: keeps track of the value in the Queue the longest 1.2 Queue Methods initialize cacates an empty Qacuc insert value uudis a copy of value to the rear of the Quelle remove remcives and returns the value at the front of the Queue, if ime exists peek returns a copy of the value at the front of the Qucae without removing it, if onc cxists is_empty relurns True if the Queue is empty, False otherwise is_full cturns True if the Qucae is full, False otherwise leno returns the number of values in the queue Any implementation of a Queue must debe these methods

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions