Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Top of Form Question 1 and 2 may be difficult to answer- these can be optionally

ID: 3558905 • Letter: T

Question

Top of Form

Question 1 and 2 may be difficult to answer- these can be optionally answered- although it would be nice to get answer

-------------------------------------------------------------------------------------------------------------------------------------------------

This may be helpful for question 1 & 2

-------------------------------------------------------

public static void main(String[] args)

{ // Create a stack and push/pop strings as directed on StdIn.

Stack s = new Stack();

while (!StdIn.isEmpty())

{

String item = StdIn.readString();

if (!item.equals("-"))

s.push(item);

else if (!s.isEmpty()) StdOut.print(s.pop() + " ");

}

StdOut.println("(" + s.size() + " left on stack)");

}

Test client for Stack

-------------------------------------------------------------------------------------------------------------------

1.3 ? Bags, Queues, and Stacks 147

-------------------------------------------------------------------------------------------------------------------

public static void main(String[] args)

{ // Create a queue and enqueue/dequeue strings.

Queue q = new Queue();

while (!StdIn.isEmpty())

{

String item = StdIn.readString();

if (!item.equals("-"))

q.enqueue(item);

else if (!q.isEmpty()) StdOut.print(q.dequeue() + " ");

}

StdOut.println("(" + q.size() + " left on queue)");

}

Test client for Queue

-----------------------------------------------------------------------------------------

Give the output printed by the book's Stack client for the input

    it was - the best - of times - - - it was - the - -

Question 1 options:

was best times of the was the it

was best times it the was the of

it was the best of times it was

Give the output printed by the book's Queue client for the input

    it was - the best - of times - - - it was - the - -

Question 2 options:

was best times of the was the it

was best times it the was the of

it was the best of times it was

Suppose x is a linked-list node and not the last node on the
list. What is the effect of the following code fragment?

x.next = x.next.next;

Question 3 options:

Inserts node t immediately after node x.

Deletes from the list the node immediately following x.

Does nothing to the list.

Creates a cycle in the list.

Suppose x is a linked-list node and not the last node on the
list. Suppose that t points to a new node that is not in the list.
What is the effect of the following code fragment?

t = x.next
x = t;

Question 4 options:

Does nothing to the list.

Deletes from the list the node immediately following x.

Inserts node t immediately after node x.

Creates a cycle in the list.

Suppose x is a linked-list node and not the last node on the
list. Suppose that t points to a new node that is not in the list.
What is the effect of the following code fragment?

t.next = x.next;
x.next = t;

Question 5 options:

Inserts node t immediately after node x.

Does nothing to the list.

Deletes from the list the node immediately following x.

Creates a cycle in the list.

Suppose x is a linked-list node and not the last node on the
list. Suppose that t points to a new node that is not in the list.
What is the effect of the following code fragment?

x.next = t;
t.next = x.next;

Question 6 options:

Does nothing to the list.

Inserts node t immediately after node x.

Creates a cycle in the list.

Deletes from the list the node immediately following x.

What does the following code fragment do to the queue q?

    Stack stack = new Stack();
    while (!q.isEmpty())
       stack.push(q.dequeue());
    while (!stack.isEmpty())
       q.enqueue(stack.pop());

was best times of the was the it

was best times it the was the of

it was the best of times it was

Explanation / Answer

Question 1 options:

was best times of the was the it

Give the output printed by the book's Queue client for the input

    it was - the best - of times - - - it was - the - -

Question 2 options:

was best times of the was the it

Suppose x is a linked-list node and not the last node on the
list. What is the effect of the following code fragment?

x.next = x.next.next;

Question 3 options:

Deletes from the list the node immediately following x.

Suppose x is a linked-list node and not the last node on the
list. Suppose that t points to a new node that is not in the list.
What is the effect of the following code fragment?

t = x.next
x = t;

Question 4 options:

Does nothing to the list.

.

Suppose x is a linked-list node and not the last node on the
list. Suppose that t points to a new node that is not in the list.
What is the effect of the following code fragment?

t.next = x.next;
x.next = t;

Question 5 options:

Inserts node t immediately after node x.

.

Suppose x is a linked-list node and not the last node on the
list. Suppose that t points to a new node that is not in the list.
What is the effect of the following code fragment?

x.next = t;
t.next = x.next;

Question 6 options:

Inserts node t immediately after node x.

.

What does the following code fragment do to the queue q?

    Stack stack = new Stack();
    while (!q.isEmpty())

was best times of the was the it

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote