Using the three properties: implement the queue interface using a circular array O array-Array object, initialized capacity o front_index-int, index where you dequeue o back_index-int, index where you enqueue Don't add or use other properties other than the three above. Wrap-around: set index back to 0 after the limit has been exceeded. Implement size, enqueue (), dequeue (). front () Size property - compute using front_index and back_index Must have two cases: Case 1: front_index <= back_index (normal) Case 2: back_index < front_index (wrap-around) enqueue(item): front (): Before array becomes full (one empty slot left), create a bigger array with 2x capacity (note: don't use expand) Copy current queue items to bigger array (make sure you keep the same queue order) Case 1: front_index < back_index (normal) Case 2: back_index < front_index (wrap-around) Update array, front_index, back_index properties Make a bigger array before it is full, because back_index always needs to refer to a blank index for enqueue dequeue (): - - add item to the next available array cell update back_index: wrap-around if exceeds index limit If empty, raise Exception ('Empty queue: cannot dequeue') Remove and return the front item Update front_index; wrap-around if exceeds index limit If array becomes empty, reset front_index = back_index = 0 If empty, raise Exception ('Empty queue: no front') Return the front item

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Using the three properties:
implement the queue interface using a circular array
▪
O array Array object, initialized capacity
O front_index-int, index where you dequeue
back_index-int, index where you enqueue
O
Don't add or use other properties other than the three above.
Wrap - around: set index back to 0 after the limit has been exceeded.
Implement size, enqueue (), dequeue (). front ()
Size property - compute using front_index and back_index
Must have two cases:
Case 1: front_index <= back_index (normal)
Case 2: back_index < front_index (wrap-around)
enqueue(item):
front ():
add item to the next available array cell
- update back_index: wrap-around if exceeds index limit
Before array becomes full (one empty slot left), create a bigger array with 2x capacity (note: don't use expand)
Copy current queue items to bigger array (make sure you keep the same queue order)
Case 1: front_index < back_index (normal)
Case 2: back_index < front_index (wrap-around)
Update array, front_index, back_index properties
Make a bigger array before it is full, because back_index always needs to refer to a blank index for enqueue
dequeue ():
-
If empty, raise Exception ('Empty queue: cannot dequeue')
Remove and return the front item
Update front_index; wrap-around if exceeds index limit
If array becomes empty, reset front_index = back_index = 0
If empty, raise Exception ('Empty queue: no front')
Return the front item
Transcribed Image Text:Using the three properties: implement the queue interface using a circular array ▪ O array Array object, initialized capacity O front_index-int, index where you dequeue back_index-int, index where you enqueue O Don't add or use other properties other than the three above. Wrap - around: set index back to 0 after the limit has been exceeded. Implement size, enqueue (), dequeue (). front () Size property - compute using front_index and back_index Must have two cases: Case 1: front_index <= back_index (normal) Case 2: back_index < front_index (wrap-around) enqueue(item): front (): add item to the next available array cell - update back_index: wrap-around if exceeds index limit Before array becomes full (one empty slot left), create a bigger array with 2x capacity (note: don't use expand) Copy current queue items to bigger array (make sure you keep the same queue order) Case 1: front_index < back_index (normal) Case 2: back_index < front_index (wrap-around) Update array, front_index, back_index properties Make a bigger array before it is full, because back_index always needs to refer to a blank index for enqueue dequeue (): - If empty, raise Exception ('Empty queue: cannot dequeue') Remove and return the front item Update front_index; wrap-around if exceeds index limit If array becomes empty, reset front_index = back_index = 0 If empty, raise Exception ('Empty queue: no front') Return the front item
Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY