(20 Points) 1. Respond to the following true/false questions.
(30 Points) 2. Consider the following conceptual representation for a linked list. head references the first node in the list. Suppose that each node points to both the next and the previous nodes as shown.
----- ----- ---- ----- --
|hello|===>|where|===>|does|===>|this |===>|go|===||
----- ----- ---- ----- --
head
Here is the definition of our node class:
class Node {
String element_;
Node next_;
Node (Node n, int e) {
next_=n;
element_=e;
}
}
boolean removeLast (Node head) {
}
(20 Points) 3. Assume the following Queue interface as we used it in Lab#3:
public interface Queue {
public boolean empty();
public boolean full();
public Queue enqueue(Object x) throws Exception;
public Queue dequeue() throws Exception;
public Object peek() throws Exception;
}
Write a method that removes all elements of a Queue, one at a time, and return the last one found on the queue. This method returns null if the queue is empty. Don't forget your try/catch.
public Object remove_all_and_return_last(Queue q) {
return ----;
}
(30 Points) 4. Here are the definitions of the stringLinkedList and the stringLinkedListItr classes:
public class stringLinkedList
{
public stringLinkedList( )
public boolean isEmpty( )
public void makeEmpty( )
}
public class stringLinkedListItr {
public stringLinkedListItr( stringLinkedList anyList )
public void insert( String x ) throws Exception
public void insertAtBeginning( String x )
public boolean find( String x )
public void remove( String x ) throws Exception
public boolean validCurrent( )
public String retrieve( )
public void first( )
public void advance( )
public String dump ()
}
// Print contents of theList
static public void printList( stringLinkedList theList ){
stringLinkedListItr itr = new stringLinkedListItr( theList );
if( theList.isEmpty( ) )
System.out.println( "Empty list" );
else
for( ; itr.validCurrent( ); itr.advance( ) )
System.out.println( itr.retrieve( ) );
}