Source of TwoPartCircularLinkedQueue.java


  1: /**
  2:    A class that implements the ADT queue by using a
  3:    two-part circular chain of nodes.
  4:  
  5:    @author Frank M. Carrano
  6:    @author Timothy M. Henry
  7:    @version 4.0
  8: */
  9: public final class TwoPartCircularLinkedQueue<T> implements QueueInterface<T>
 10: {
 11:    private Node queueNode; // References first node in queue
 12:    private Node freeNode;  // References node after back of queue
 13:    
 14:    public TwoPartCircularLinkedQueue()
 15:    {
 16:       freeNode = new Node(null, null);
 17:       freeNode.setNextNode(freeNode);
 18:       queueNode = freeNode;
 19:    } // end default constructor
 20: 
 21:    //  < Implementations of the queue operations go here. >
 22:    //  . . .
 23: 
 24:         private class Node
 25:         {
 26:                 private T    data;  // Queue entry
 27:                 private Node next;  // Link to next node
 28:       
 29:                 private Node(T dataPortion)
 30:                 {
 31:                         data = dataPortion;
 32:                         next = null;
 33:                 } // end constructor
 34:                 
 35:                 private Node(T dataPortion, Node linkPortion)
 36:                 {
 37:                         data = dataPortion;
 38:                         next = linkPortion;
 39:                 } // end constructor
 40:       
 41:                 private T getData()
 42:                 {
 43:                         return data;
 44:                 } // end getData
 45:       
 46:                 private void setData(T newData)
 47:                 {
 48:                         data = newData;
 49:                 } // end setData
 50:       
 51:                 private Node getNextNode()
 52:                 {
 53:                         return next;
 54:                 } // end getNextNode
 55:                 
 56:                 private void setNextNode(Node nextNode)
 57:                 {
 58:                         next = nextNode;
 59:                 } // end setNextNode
 60:         } // end Node
 61: } // end TwoPartCircularLinkedQueue