A real-time traffic simulation showcasing queue data structures & traffic management. Includes multiple vehicle types, traffic lights, and priority-based queue handling.
- 🏎️ Real-time 4-way intersection simulation
- 🚓🚑🚒 Multiple vehicle types with priority handling
- 🚦 Dynamic traffic light system
- 🔄 Vehicles can turn left, or go straight
- 🎯 Queue-based traffic management
You'll need:
- 🖥️ GCC/G++ compiler
- 🎮 SDL2 library
- 🏗️ MinGW (for Windows)
- 🔗 Download SDL2
- 📂 Extract contents to your project directory
- 🏗 Create folders if missing:
include/(for headers)lib/(for library files)bin/(for output)
DSA-Queue-Simulator/
├── include/ # Header files
├── lib/ # Library files
├── src/ # Source files
├── bin/ # Executables
└── README.md
- Clone the repo:
git clone https://github.com/zen4FR/dsa-queue-simulator.git
cd DSA-Queue-Simulator- Compile:
g++ -Iinclude -Llib -o bin/main.exe src/main.c src/traffic_simulation.c -lmingw32 -lSDL2main -lSDL2g++ -Iinclude -Llib -o bin/main.exe src/main.c src/traffic_simulation.c -lmingw32 -lSDL2main -lSDL2- Start the vehicle generator:
./bin/generator- In another terminal, start the main simulation:
./bin/main- 🚗 Watch vehicles navigate the intersection!
- ❌ Click the close button (X) to exit.
- 🔵 Regular cars
- 🔴 Ambulances
- 🔷 Police cars
- 🟠 Fire trucks
- 🚦 Queue System: Each lane manages its own queue.
- 🚨 Priority Handling: Emergency vehicles go first.
- 🔄 Traffic Light Cycles: Automated red/green transitions.
- 🔁 Turn Management: Vehicles can turn left, right, or go straight.
typedef struct Node {
Vehicle vehicle;
struct Node* next;
} Node;
typedef struct {
Node* front;
Node* rear;
int size;
} Queue;typedef enum {
STATE_MOVING,
STATE_STOPPING,
STATE_STOPPED,
STATE_TURNING
} VehicleState;- 🍴 Fork the repo
- 🌿 Create a branch (
git checkout -b feature/AmazingFeature) - 💾 Commit changes (
git commit -m 'Add AmazingFeature') - 🚀 Push (
git push origin feature/AmazingFeature) - 🔥 Open a Pull Request
- 📖 SDL2 Documentation
- 📘 Queue Data Structure: Introduction to Algorithms, CLRS (Cormen, Leiserson, Rivest, Stein)
- 🚑 Traffic Flow Theory: Highway Capacity Manual (Transportation Research Board)
- ❤️ SDL2 Dev Team
