We are performing the following operations on a Deque implemented using an array
ID: 673291 • Letter: W
Question
We are performing the following operations on a Deque implemented using an array. The initial
capacity of the array is 5 and the array doubles whenever the deque reaches its capacity. Please show
the physical state (draw the array cells) of the array after each of the operations. For the array elements
with “junk” values, leave any existing value in the array but cross it out. Show next to the array the
values of the lo and hi indices.
a) pushFront C lo= hi=
b) pushFront A
c) pushBack Z
d) popFront
e) pushBack U
f) pushFront K
g) popBack
h) pushBack J
i) pushFront H
j) pushBack P
k) popFront
Explanation / Answer
lo hi
0 0
a) pushFront C
------------------
|C | - | - | - | - | 1 0
------------------
/
lo hi
b) pushFront A
------------------
|C | A | - | - | - | 2 0
------------------
/
lo hi
c) pushBack Z
------------------
|C | A | - | - | Z | 2 1
------------------
/
lo hi
d) popFront
------------------
| A | - | - | - | Z | 1 1
------------------
/
lo hi
c) pushBack Z
------------------
| A | - | - | Z | Z | 1 2
------------------
/
lo hi
e) pushBack U
------------------
| A | - | Z | Z | U | 1 3
------------------
/
lo hi
f) pushFront K
------------------
| A | Z | Z | U | K | 1 4
------------------
/
lo hi
g) popBack
------------------
| A | - | Z | Z | U | 1 3
------------------
/
lo hi
h) pushBack J
------------------
| A | Z | Z | U | J | 1 4
------------------
/
lo hi
i) pushFront H
----------------------------------------
| H | A | - | - | - | - | Z | Z | U | J | 2 4
----------------------------------------
/
lo hi
j) pushBack P
----------------------------------------
| H | A | - | - | - | Z | Z | U | J | P | 1 5
----------------------------------------
/
lo hi
k) popFront
----------------------------------------
| A | - | - | - | - | Z | Z | U | J | P | 0 5
----------------------------------------
/
lo hi
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.