Code Notes: Queue

Topics covered: Queue operations

Link to source code: http://www.cs.tufts.edu/comp/15/examples/queues/queue.h

#include "sll.h"

/// A queue (FIFO) implementation using singly linked list                                                                                                                                                     
class queue {

 public:
  /// Don't need to overwrite the default constructor, destructor,                                                                                                                                             
  /// copy constructor or assignment operator.                                                                                                                                                                 

  /// Push aValue into the back of the queue                                                                                                                                                                   
  void enqueue(int aValue)
  {
    mLL.addBack(aValue);
  }
  /// Pop out the value from the front of the queue                                                                                                                                                            
  void dequeue()
  {
    if (isEmpty()) {
      cout << "Queue is empty. Cannot dequeue!" << endl;
      return;
    }
    mLL.removeFront();
  }
  /// Fetch the front value from the queue (without deleting it)                                                                                                                                               
  int front()
  {
    return mLL.front();
  }
  /// Check whether the queue is empty                                                                                                                                                                         
  bool isEmpty()
  {
    return mLL.isEmpty();
  }
 private:
  SLinkedList mLL;

};