Gator Library
An implementation of the Red-Black Tree and Priority queue data structure in C++.
|
A priority queue implementation for reservations.This class represents a priority queue that stores reservations. Reservations are stored in a heap data structure, where the highest priority reservation is always at the top. Reservations are ordered based on their priority. More...
#include <priority_queue.hpp>
Public Member Functions | |
void | push (reservation newReservation) |
Push a new reservation into the priority queue. | |
void | pop () |
Remove the highest priority reservation from the priority queue. | |
reservation | top () |
Get the highest priority reservation from the priority queue. | |
bool | empty () |
Check if the priority queue is empty. | |
int | size () |
Get the size of the priority queue. | |
pq_reservation () | |
Construct a new pq_reservation object. | |
~pq_reservation () | |
Destroy the pq_reservation object. | |
Private Member Functions | |
void | heapify (int index) |
Heapify the heap starting from the given index. | |
Private Attributes | |
std::vector< reservation > | heap |
A priority queue implementation for reservations.
This class represents a priority queue that stores reservations. Reservations are stored in a heap data structure, where the highest priority reservation is always at the top. Reservations are ordered based on their priority.
pq_reservation::pq_reservation | ( | ) |
Construct a new pq_reservation object.
This is the constructor for the pq_reservation class.
pq_reservation::~pq_reservation | ( | ) |
Destroy the pq_reservation object.
This is the destructor for the pq_reservation class.
bool pq_reservation::empty | ( | ) |
Check if the priority queue is empty.
This function checks if the priority queue is empty.
|
private |
Heapify the heap starting from the given index.
This function rearranges the elements in the heap to maintain the heap property. It compares the element at the given index with its children and swaps them if necessary.
index | The index to start heapifying from. |
void pq_reservation::pop | ( | ) |
Remove the highest priority reservation from the priority queue.
This function removes the highest priority reservation from the priority queue and maintains the heap property.
void pq_reservation::push | ( | reservation | newReservation | ) |
Push a new reservation into the priority queue.
This function adds a new reservation to the priority queue and maintains the heap property.
newReservation | The reservation to be added. |
int pq_reservation::size | ( | ) |
Get the size of the priority queue.
This function returns the number of reservations in the priority queue.
reservation pq_reservation::top | ( | ) |
Get the highest priority reservation from the priority queue.
This function returns the highest priority reservation from the priority queue without removing it.
|
private |
The heap storing the reservations.