Skip to content

Commit d6927f1

Browse files
authored
Merge pull request #38 from MJ-thunder/fix/add-graph-color
Updated graph.h with color attribute and clean struct definitions
2 parents 21a3c66 + 29de9e3 commit d6927f1

1 file changed

Lines changed: 25 additions & 27 deletions

File tree

cpp/include/algorithms/graph.h

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#pragma once
2-
#include <vector>
32
#include <string>
3+
#include <vector>
44
#include <unordered_map>
55

6-
// Forward declarations to avoid circular dependencies
76
struct GraphNode {
87
int id;
98
std::string label;
109
double x, y;
11-
12-
GraphNode(int id = 0, const std::string& label = "", double x = 0.0, double y = 0.0);
10+
std::string color;
11+
12+
GraphNode(int id, const std::string& label = "", double x = 0.0, double y = 0.0, const std::string& color = "white");
1313
};
1414

1515
struct GraphEdge {
1616
int from, to;
1717
double weight;
1818
bool directed;
19-
20-
GraphEdge(int from = 0, int to = 0, double weight = 1.0, bool directed = false);
19+
std::string color;
20+
21+
GraphEdge(int from, int to, double weight = 1.0, bool directed = false, const std::string& color = "black");
2122
};
2223

2324
struct GraphStep {
@@ -28,27 +29,24 @@ struct GraphStep {
2829
std::unordered_map<int, double> distances;
2930
std::unordered_map<int, int> parents;
3031
std::string operation;
31-
32-
GraphStep(const std::string& operation = "");
32+
33+
GraphStep(const std::string& operation);
3334
};
3435

35-
class Graph {
36-
private:
37-
std::vector<GraphNode> nodes;
38-
std::vector<GraphEdge> edges;
39-
std::vector<std::vector<int>> adjList;
40-
std::vector<std::vector<std::pair<int, double>>> weightedAdjList;
41-
42-
public:
43-
void addNode(const GraphNode& node);
44-
void addEdge(const GraphEdge& edge);
45-
void buildAdjacencyList();
46-
47-
std::vector<GraphStep> bfs(int start);
48-
std::vector<GraphStep> dfs(int start);
49-
std::vector<GraphStep> dijkstra(int start, int end = -1);
50-
std::vector<GraphStep> aStar(int start, int end);
51-
std::vector<GraphStep> kruskal();
52-
std::vector<GraphStep> prim();
36+
struct SortingStep {
37+
std::vector<int> array;
38+
std::vector<int> highlighted;
39+
std::vector<int> comparing;
40+
std::string operation;
41+
int operations_count;
42+
std::string time_complexity;
43+
std::string space_complexity;
44+
45+
SortingStep(const std::vector<int>& array,
46+
const std::vector<int>& highlighted,
47+
const std::vector<int>& comparing,
48+
const std::string& operation,
49+
int operations_count,
50+
const std::string& time_complexity,
51+
const std::string& space_complexity);
5352
};
54-

0 commit comments

Comments
 (0)