예제 #1
0
        // Method to add an key to the queue.
        public void enqueue(int key)
        {
            // Create a new LL node
            QNode temp = new QNode(key);

            // If queue is empty, then new
            // node is front and rear both
            if (this.rear == null)
            {
                this.front = this.rear = temp;
                return;
            }

            // Add the new node at the
            // end of queue and change rear
            this.rear.next = temp;
            this.rear      = temp;
        }
예제 #2
0
        // Method to remove an key from queue.
        public void dequeue()
        {
            // If queue is empty, return NULL.
            if (this.front == null)
            {
                return;
            }

            // Store previous front and
            // move front one node ahead
            QNode temp = this.front;

            this.front = this.front.next;

            // If front becomes NULL,
            // then change rear also as NULL
            if (this.front == null)
            {
                this.rear = null;
            }
        }
예제 #3
0
 // constructor to create
 // a new linked list node
 public QNode(int key)
 {
     this.key  = key;
     this.next = null;
 }
예제 #4
0
 public Queue()
 {
     this.front = this.rear = null;
 }