Source of LinkedQueue.java


  1: /**
  2:    A class that implements a queue of objects by using
  3:    a chain of linked nodes that has both head and tail references.
  4:  
  5:    @author Frank M. Carrano
  6:    @author Timothy M. Henry
  7:    @version 5.0
  8: */
  9: public final class LinkedQueue<T> implements QueueInterface<T>
 10: {
 11:    private Node firstNode; // References node at front of queue
 12:    private Node lastNode;  // References node at back of queue
 13:           
 14:         public LinkedQueue()
 15:         {
 16:                 firstNode = null;
 17:                 lastNode = null;
 18:         } // end default constructor

 20: //  < Implementations of the queue operations go here. >
 21: //  . . .

 23:         private class Node
 24:         {
 25:                 private T    data; // Entry in queue
 26:                 private Node next; // Link to next node
 27:       
 28:                 private Node(T dataPortion)
 29:                 {
 30:                         data = dataPortion;
 31:                         next = null;
 32:                 } // end constructor
 33:                 
 34:                 private Node(T dataPortion, Node linkPortion)
 35:                 {
 36:                         data = dataPortion;
 37:                         next = linkPortion;
 38:                 } // end constructor
 39:       
 40:                 private T getData()
 41:                 {
 42:                         return data;
 43:                 } // end getData
 44:       
 45:                 private void setData(T newData)
 46:                 {
 47:                         data = newData;
 48:                 } // end setData
 49:       
 50:                 private Node getNextNode()
 51:                 {
 52:                         return next;
 53:                 } // end getNextNode
 54:                 
 55:                 private void setNextNode(Node nextNode)
 56:                 {
 57:                         next = nextNode;
 58:                 } // end setNextNode
 59:         } // end Node
 60: } // end LinkedQueue