Name: ___________________________________________________________________
1-2. The code below is an incorrect implementation of the insertLast(T) method of the class LinkedListClass described in the textbook.
public void insertLast(T newClass)
{
LinkedListNode newNode;
newNode = new LinkedListNode(newItem, first);
if (first == null)
{
first = newNode;
last = newNode;
}
else
last = newNode;
count++;
}
insertLast(T) method.
3. In the linked list implementation of a stack, write a code for pushing an element 1. Trace your code on the example of a stack which originally has elements 2 and 3, with 2 being the top element.
4-5. Consider the following arithmetic expression:
peek(), pop(), and push() methods, show how a stack can be used to support the evaluation of the expression in its postfix representation.
6. The implementation of the
LinkedListClass in the textbook includes an instance variable called count of type int.
LinkedListClass not having this instance variable.
7. In the array implementation of a queue, show what will happen if you first add to the queue elements 3, 4, 5, and 6, and then delete one element from the queue.
8. Using the class
UnorderedLinkedList as defined in the textbook, consider the following Java statements:
UnorderedLinkedListWhat is the output of this program segment?list = new UnorderedLinkedList (); list.insertLast(2); list.insertFirst(list.front()); list.insertLast(4); list.insertFirst(3); list.insertLast(list.back()); list.insertFirst(5); list.print();