Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit 0b2edf4

Browse files
committed
Implement loading adjacencyList
1 parent 56e4ae6 commit 0b2edf4

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

DirectedGraph.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,18 @@ void DirectedGraph::loadRawDataToMatrix(std::vector<int> rawData) {
5353
}
5454

5555
void DirectedGraph::loadRawDataToList(std::vector<int> rawData) {
56+
adjacencyList.clear();
57+
int i = 0;
58+
59+
int numberOfEdges = rawData[i++];
60+
61+
adjacencyList.resize(rawData[i++]);
62+
63+
for (int j = 0; j < numberOfEdges; j++) {
64+
int edgeBeginning = rawData[i++];
65+
int edgeEnd = rawData[i++];
66+
int edgeValue = rawData[i++];
5667

68+
adjacencyList[edgeBeginning].push_front({edgeEnd, edgeValue});
69+
}
5770
}

UndirectedGraph.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,23 @@ void UndirectedGraph::loadRawDataToMatrix(vector<int> rawData) {
5353
}
5454

5555
void UndirectedGraph::loadRawDataToList(std::vector<int> rawData) {
56+
adjacencyList.clear();
57+
int i = 0;
58+
59+
int numberOfEdges = rawData[i++];
60+
61+
adjacencyList.resize(rawData[i++]);
62+
63+
for (int j = 0; j < numberOfEdges; j++) {
64+
int edgeBeginning = rawData[i++];
65+
int edgeEnd = rawData[i++];
66+
int edgeValue = rawData[i++];
67+
68+
adjacencyList[edgeBeginning].push_front({edgeEnd, edgeValue});
5669

70+
if (edgeBeginning == edgeEnd)
71+
continue;
72+
73+
adjacencyList[edgeEnd].push_front({edgeBeginning, edgeValue});
74+
}
5775
}

0 commit comments

Comments
 (0)