Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question to be answerd CircArrayQueue representation for queue = [R, S, T]:4 in which T has an array index greater than R, but first is

Question to be answerd

CircArrayQueue representation for queue = [R, S, T]:4 in which T has an array index greater than R, but first is not 0.

contents = ...

first = ...

length = ...

capacity = ...

CircArrayQueue representation for queue = [R, S, T]:4 in which T has an array index less than R.

contents = ...

first = ...

length = ...

capacity = ...

Write the queue abstraction corresponding to the CircArrayQueue representation: contents = [A, B, C, D, E] and first =3 and length = 4.

queue = ...

Give both the representation and abstraction for the CircArrayQueue built using the following code sequence (assume an initial array contains all null values)

Queue queue = new CircArrayQueue<>(4);

queue.enqueue("A");

queue.enqueue("B");

String s1 = queue.dequeue();

queue.enqueue("C");

String s2 = queue.dequeue();

queue.enqueue("D");

queue.enqueue(s1);

contents = ...

first = ...

length = ...

capacity = ...

queue = ...

We implemented our circular array queue with fields first and length. But we could have just as easily implemented the queue with fields first and last (where last is the index of the last element in the queue) and derived length. Complete the implementation of the length method below with an expression that only uses fields first, last, and capacity, and arithmetic operations (including %). The method assumes that the length is 0 when first is -1, so you just need to worry about the cases where the length is not 0.

public int length() {

if (first == -1) {

return 0;

} else {

return ...

}

}

Consider the diagram in Figure 1 that shows the representation of LinkedQueue

[A, B, C]:6 along with a temporary node that was created and holds the element X. Suppose our queue had an inject operation that allowed us to add an element at the beginning of the queue (rather than enqueue, which adds an element to the end). What would be the next two steps in order to get the queue [X, A, B, C]:6? Choose from one of the following statements for your steps, where [var1] and [var2] are either temp, first, or last.

a.Relocate [var1] to [var2]'s node

b.Redirect [var1]'s link to [var2]'s node

c.Make [var] follow its link

step 1:

step 2:

What is a one-line command (in code) for "Make first follow its link"? (Ex: in Figure1, first would end up at the node containing B) Hint: It involves an assignment.

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

Students also viewed these Programming questions