Question
JAVA Help: 6) (5 pts) A circularly linked list is used to represent a Queue . A single variable P is used to access the
JAVA Help:
6) (5 pts) A circularly linked list is used to represent a Queue. A single variable P is used to access the Queue. To which Node should P point such that both the operations enqueue (item) and item = dequeue() can be performed in constant time: O(1) no looping necessary?
7) (6 pts) Show what is written by the following segment of code:
String item0 = ;
String item1 = EE;
String item2 = B + item1;
String item3 = P;
push (item2);
push (item1);
push (item3 + item1);
item0 = stack.peek();
pop();
push (item2 + item3);
push (item0);
push (item0 + item3);
item0 = stack.peek();
pop();
print (Item0: + item0);
print (Item1: + item1);
print (Item2: + item2);
print (Item3: + item3);
while (!stack.isEmpty())
item0 = stack.peek();
pop();
print (Item: + item0);
8)
(5 pts) A single array, stk[MAXELEMS], is used to implement two stacks. The two stacks are grown in an array one from each end. Two variables, head1 and head2 (head1 < head2), hold the index of the location of the top element in each of the stacks. Which of the following is the best for implementing the check for a full stack, given we want a space efficient algorithm.
(head1 = MAXELEMS / 2) and (head2 = MAXELEMS / 2+1)
head1 + head2 = MAXELEMS
(head1 = MAXELEMS / 2) or (head2 = MAXELEMS)
head1 = head2 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started