Skip to content

GareginChorokhyan/PriorityQueue

Repository files navigation

Custom Priority Queue (C++)

This project implements a custom generic priority queue container in modern C++, similar to std::priority_queue, with configurable:

  • value type
  • underlying container
  • comparison strategy

It also includes a small demo in main.cpp.

Project Structure

  • priority_queue.hpp - declaration of priorityQueue template class and deduction guides
  • priority_queue.impl.hpp - implementation of all priorityQueue member functions
  • Algorithm.hpp - declarations of heap utility algorithms in namespace Heap
  • Algorithm.impl.hpp - implementation of heap algorithms (makeHeap, pushHeap, popHeap, Heapify)
  • main.cpp - usage examples and output demo

Architecture

The design is split into two layers:

  1. Container layer (priorityQueue)
    • Public API: push, pop, top, empty, size, emplace, swap
    • Owns data (Container c) and comparison object (Compare cmp)
  2. Algorithm layer (Heap namespace)
    • Stateless heap procedures that operate on iterator ranges
    • Called internally by priorityQueue to maintain heap invariants

High-Level Flow

  • Constructor from container/range -> Heap::makeHeap(...)
  • push / emplace -> append element -> Heap::pushHeap(...)
  • pop -> Heap::popHeap(...) -> remove last element
  • top -> returns c.front() (heap root)

Class and Dependency Diagram

flowchart TD
    A[main.cpp] --> B[priorityQueue<T, Container, Compare>]
    B --> C[Container c]
    B --> D[Compare cmp]

    B --> E[Heap::makeHeap]
    B --> F[Heap::pushHeap]
    B --> G[Heap::popHeap]

    G --> H[Heap::Heapify]
    H --> I[Heap::getLeft]
    H --> J[Heap::getRight]
Loading

Dependency Notes

  • priority_queue.hpp includes Algorithm.hpp
  • priority_queue.impl.hpp depends on Heap functions declared in Algorithm.hpp
  • Algorithm.hpp includes Algorithm.impl.hpp (template implementation pattern)
  • main.cpp depends only on priority_queue.hpp (plus standard library headers)

Build and Run

Simple compile command:

g++ main.cpp

Run:

  • Linux:
./a.out
  • Windows:
./a.exe

Example Usage

priorityQueue<int> maxQ;
maxQ.push(10);
maxQ.push(3);
maxQ.push(7);

std::cout << maxQ.top() << '\n'; // highest-priority element
maxQ.pop();

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages