Projects Inventory

Queue Implementation Gaming Project in C++

Explanation

  1. Queue Class:
    • The Queue class is implemented using a std::vector<int> to store the elements.
    • Advertisement
    • It maintains two indices: frontIndex and rearIndex, which represent the positions of the front and rear elements in the queue.
  2. Enqueue Operation:
    • The enqueue(int value)
      Advertisement
      method adds an element to the rear of the queue by pushing it to the back of the vector and increments rearIndex.
  3. Dequeue Operation:
    • The dequeue() method removes and returns the element at the front of the queue by accessing the element at frontIndex and then increments frontIndex. If the queue is empty, it throws an exception.
  4. Front Operation:
    • The front() method returns the element at the front of the queue without removing it. If the queue is empty, it throws an exception.
    • Advertisement
  5. isEmpty Operation:
    • The isEmpty() method checks if the queue is empty by comparing frontIndex and rearIndex.
  6. Size Operation:
    • The size() method returns the current size of the queue by calculating the difference between rearIndex and frontIndex.
Exit mobile version