A High-End, STL-Free Data Structures & Algorithms Engine in C++
This repository contains the design and implementation of an in-memory Ride-Sharing Dispatch & Trip Management System (similar to Uber or Careem).
Built strictly from scratch without relying on C++ Standard Template Library (STL) containers, this project focuses on low-level data structures, graph traversal algorithms, finite state machines, and dynamic rollback mechanics to demonstrate efficient memory control and custom algorithmic design.
The architecture follows modular Object-Oriented Programming (OOP) principles where each component handles a single responsibility:
City: Manages the geographic map network.Driver&Rider: Core entity models with status tracking.Trip: Encapsulates state-machine transitions for trip lifecycles.DispatchEngine: Core matching logic pairing riders with the nearest drivers.RollbackManager: LIFO transaction engine for undo operations.RideShareSystem: Central controller interface coordinating system components.main.cpp: Comprehensive test harness verifying system capabilities.
- Structure: Represented using an Adjacency Matrix where nodes denote locations and edges denote distance weights.
- Routing: Uses Dijkstra’s Algorithm to compute the global shortest paths between pickup and drop-off points without STL dependencies.
- Drivers are tracked using ID, real-time location, and availability status.
- Efficiently stored in fixed-size arrays with strict constructor-based dynamic memory initialization.
- Managed using a deterministic finite state machine to avoid race conditions:
$$\text{REQUESTED} \longrightarrow \text{ASSIGNED} \longrightarrow \text{COMPLETED}$$ $$\text{REQUESTED / ASSIGNED} \longrightarrow \text{CANCELLED}$$
- Pairs trip requests with the optimal available driver using a greedy approach integrated with Dijkstra’s shortest path output.
- Implements a custom LIFO Stack enabling instant
$\mathcal{O}(1)$ transactional rollbacks for operations like trip cancellations.
| Module / Operation | Data Structure / Algorithm | Time Complexity | Space Complexity |
|---|---|---|---|
| Shortest Path | Dijkstra's Algorithm | ||
| Driver Matching | Greedy Proximity Search | ||
| State Mutation | Finite State Machine | ||
| System Rollback | Custom LIFO Stack |
Where $V$ = Map Locations, $D$ = Total Drivers, and $S$ = Rollback History Depth.
The engine includes a suite of test cases integrated into main.cpp validating:
- Shortest path routing correctness.
- Dynamic driver reassignments upon trip cancellation.
- Edge-case handling (cancelling completed or non-existent trips).
- LIFO stack state restoration.
- C++ Compiler: GCC / G++ (MinGW on Windows, Clang on macOS)
- Compile all source files:
g++ *.cpp -o main.exe