Question

5) Assuming that the following items are stored in a double ended queue called myDeque: 2,...

5) Assuming that the following items are stored in a double ended queue called myDeque: 2, 3, 1, 0, -1. Draw memory diagrams showing how moveToBack method will change the pointers (step-by-step) for the following scenarios - each scenario starts with the original content of the queue:
1. myDeque.moveToBack(3) - the content of myDeque is now: 2 1 0 -1 3


2. myDeque.moveToBack(1) - the content of myDeque is now: 2 3 0 -1 1


3. myDeque.moveToBack(-1) - the content of myDeque is now: 2 3 1 0 -1


4. myDeque.moveToBack(5) - the content of myDeque is now: 2 3 1 0 -1


Homework Answers

Answer #1

The original contect of the myDeque is as follows:

2 3 1 0 -1

^Front ^Rear

moveToBack(component c): This method moves c to the back of the queue, where c is the component to be moved.

Deque (Double ended queue) can be implemented in 2 ways - Linked list deque and Dynamic array queue

1. myDeque.moveToBack(3)

Here I am implementing this in Linked list Deque.

In linked list deque each node has pointer to the next node, when 3 is pushed back, the pointer pointing to 3 now points to the next value in queue and rear node pointer points to value which is pushed back i.e. 3 in our case.

2. myDeque.moveToBack(1)

Here I am implementing it in Dynamic array queue, this directly moves the values to the front stack when a value is removed. So the value 0, -1 are moved to the corresponding front stacks and 1 to the rear end.

3. myDeque.moveToBack(-1)

Here alreay -1 is in the rear end, when it tries to puch -1 to rear end. The rear end pointer is already pointing to -1. So no change in Deque.

2 3 1 0 -1

4. myDeque.moveToBack(5)

In this case it tries to find value 5, when it fails to find this value throws an error. But the Deque remains unchanged.

2 3 1 0 -1
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Set Operations In questions 7 and 8 Let A = {0, 2, 4, 6}, B =...
Set Operations In questions 7 and 8 Let A = {0, 2, 4, 6}, B = {0, 1, 2, 3}, and C = {4, 5, 6}. U = {x∈ℤ| 0≤x≤10} 7. Find (A ∪ B) – C’. 8. Find C ∩ (A’ ⊕ B’) Venn Diagrams Draw Venn diagrams for the following set operations. Show each step and label the sets as well as what the diagram is showing Ex: if the Venn diagram is showing C’, label the rectangle...
A. For the following reactions, write the possible products assuming a double displacement reaction has occurred....
A. For the following reactions, write the possible products assuming a double displacement reaction has occurred. Be sure to balance the charges on the compounds . 1). CuCl2(aq) + Fe2S3(aq)  2). CuSO4(aq) + Na2CO3(aq)  B. Write the ionization of these compounds. 1). 2Na2C03(aq)  2). Fe2(SO4) (aq)  3). CaCO3(s)  4). CO2 (g)  5). Na2CO3(aq)  C. Write the complete molecular equation, the complete ionic equation, and the net ionic equation for the following reaction. Pb(NO3)2(aq)...
Q5: Define the following items? 1-Sensor; 2- Signal conditioner; 3- Zero error; 4- Accuracy; 5- Hysteresis;...
Q5: Define the following items? 1-Sensor; 2- Signal conditioner; 3- Zero error; 4- Accuracy; 5- Hysteresis; Q5: Define the following items? 1-Sensor; 2- Signal conditioner; 3- Zero error; 4- Accuracy; 5- Hysteresis;
1. An array has an index of [5] at the starting address of 200. It has...
1. An array has an index of [5] at the starting address of 200. It has 3 words per memory cell, determine loc[3],loc[4] and NE. (3 Marks: 1 mark for each) 2. A 2-D array defined as A[10 , 5] requires 4 words of storage space for each element. Calculate the address of A[4,3] given the base address as 250 • If the array is stored in Row-major form • If the array is stored in Column-major form 3. Write...
Consider the following set of frequent 3-itemsest: {1, 2, 3}, {1, 2, 4}, {1, 2, 5},...
Consider the following set of frequent 3-itemsest: {1, 2, 3}, {1, 2, 4}, {1, 2, 5}, {1, 3, 4}, {1, 3, 5}, {2, 3, 4}, {2, 3, 5}, {3, 4, 5}. Assume that there are only five items in the data set. a. List all candidate 4-itemsets obtained by a candidate generation procedure using the Fk-1 x F1 merging strategy. b. List all candidate 4-itemsets obtained by the candidate generation procedure in Apriori. c. List all candidate 4-itemsets that survive...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n ==...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n == 0)    return 0; else    return n * f(n - 1); } A. 120 B. 60 C. 1 D. 0 10 points    QUESTION 2 Which of the following statements could describe the general (recursive) case of a recursive algorithm? In the following recursive function, which line(s) represent the general (recursive) case? void PrintIt(int n ) // line 1 { // line 2...
In Visual Studio, create a program that provides the following items: 1 Textbox control 2 Picturebox...
In Visual Studio, create a program that provides the following items: 1 Textbox control 2 Picturebox control 3 int datatype 4 double datatype 5 strings 6 comment each line of code that you put into the form1.cs 7 label control 8 button control The program can be about anything you want. It should be a functional program. Program Items worth (40pts (5pts per item) ) Creativity of your program worth (30pts) Functionality worth (30pts) Submit your (form cs file) and...
Given the following data, develop MRP tables and indicate the Planned order releases for all items....
Given the following data, develop MRP tables and indicate the Planned order releases for all items. A is an MPS item. A needs 2 C's and 3 F’s. F needs 3 C’s. (I eliminated scheduled receipts since the problem did not have scheduled receipts.) Period 6 7 8 GR-A 400 0 300 On hand inventory for all items is 200 and lead time for A is 1 period, and LT for all other items is 2 periods. Use lot-for-lot for...
Given the following data, develop MRP tables and indicate the Planned order releases for all items....
Given the following data, develop MRP tables and indicate the Planned order releases for all items. A is an MPS item. A needs 2 C's and 3 F’s. F needs 3 C’s. (I eliminated scheduled receipts since the problem did not have scheduled receipts.) Period 6 7 8 GR-A 400 0 300 On hand inventory for all items is 200 and lead time for A is 1 period, and LT for all other items is 2 periods. Use lot-for-lot for...
Question: 1. Based on the table, answer the following questions. (1) (2) (3) (4) (5) (6)...
Question: 1. Based on the table, answer the following questions. (1) (2) (3) (4) (5) (6) (7) K L Q MPK APK APL VMPK 0 20 0 - - - - 1 20 50 100 2 20 150 200 3 20 300 300 4 20 400 200 5 20 450 100 6 20 475 50 7 20 475 0 8 20 450 -50 9 20 400 -100 10 20 300 -200 11 20 150 -300 A firm’s product sells for...