From 29de9e33b6f3fb1a01ccb24be590504fed6c9c86 Mon Sep 17 00:00:00 2001 From: MJ-thunder Date: Sat, 4 Oct 2025 17:38:00 +0530 Subject: [PATCH] Updated graph.h with color attribute and clean struct definitions --- cpp/include/algorithms/graph.h | 52 ++++++++++++++++------------------ 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/cpp/include/algorithms/graph.h b/cpp/include/algorithms/graph.h index f208677..8dff161 100644 --- a/cpp/include/algorithms/graph.h +++ b/cpp/include/algorithms/graph.h @@ -1,23 +1,24 @@ #pragma once -#include #include +#include #include -// Forward declarations to avoid circular dependencies struct GraphNode { int id; std::string label; double x, y; - - GraphNode(int id = 0, const std::string& label = "", double x = 0.0, double y = 0.0); + std::string color; + + GraphNode(int id, const std::string& label = "", double x = 0.0, double y = 0.0, const std::string& color = "white"); }; struct GraphEdge { int from, to; double weight; bool directed; - - GraphEdge(int from = 0, int to = 0, double weight = 1.0, bool directed = false); + std::string color; + + GraphEdge(int from, int to, double weight = 1.0, bool directed = false, const std::string& color = "black"); }; struct GraphStep { @@ -28,27 +29,24 @@ struct GraphStep { std::unordered_map distances; std::unordered_map parents; std::string operation; - - GraphStep(const std::string& operation = ""); + + GraphStep(const std::string& operation); }; -class Graph { -private: - std::vector nodes; - std::vector edges; - std::vector> adjList; - std::vector>> weightedAdjList; - -public: - void addNode(const GraphNode& node); - void addEdge(const GraphEdge& edge); - void buildAdjacencyList(); - - std::vector bfs(int start); - std::vector dfs(int start); - std::vector dijkstra(int start, int end = -1); - std::vector aStar(int start, int end); - std::vector kruskal(); - std::vector prim(); +struct SortingStep { + std::vector array; + std::vector highlighted; + std::vector comparing; + std::string operation; + int operations_count; + std::string time_complexity; + std::string space_complexity; + + SortingStep(const std::vector& array, + const std::vector& highlighted, + const std::vector& comparing, + const std::string& operation, + int operations_count, + const std::string& time_complexity, + const std::string& space_complexity); }; -