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

Commit 120aee1

Browse files
committed
Deny loops in graphs
1 parent 0f641c1 commit 120aee1

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

DirectedGraph.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ void DirectedGraph::loadRawDataToMatrix(std::vector<int> rawData) {
4747
int edgeEnd = rawData[i++];
4848
int edgeValue = rawData[i++];
4949

50+
if (edgeBeginning == edgeEnd) {
51+
incidenceMatrix.clear();
52+
throw "Petle sa nieakceptowane!";
53+
}
54+
5055
incidenceMatrix[j][edgeEnd] = edgeValue * -1;
5156
incidenceMatrix[j][edgeBeginning] = edgeValue;
5257
}
@@ -65,6 +70,11 @@ void DirectedGraph::loadRawDataToList(std::vector<int> rawData) {
6570
int edgeEnd = rawData[i++];
6671
int edgeValue = rawData[i++];
6772

73+
if (edgeBeginning == edgeEnd) {
74+
incidenceMatrix.clear();
75+
throw "Petle sa nieakceptowane!";
76+
}
77+
6878
adjacencyList[edgeBeginning].push_front({edgeEnd, edgeValue});
6979
}
7080
}

UndirectedGraph.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ void UndirectedGraph::loadRawDataToMatrix(vector<int> rawData) {
4747
int edgeEnd = rawData[i++];
4848
int edgeValue = rawData[i++];
4949

50+
if (edgeBeginning == edgeEnd) {
51+
incidenceMatrix.clear();
52+
throw "Petle sa nieakceptowane!";
53+
}
54+
5055
incidenceMatrix[j][edgeEnd] = edgeValue;
5156
incidenceMatrix[j][edgeBeginning] = edgeValue;
5257
}
@@ -65,11 +70,12 @@ void UndirectedGraph::loadRawDataToList(std::vector<int> rawData) {
6570
int edgeEnd = rawData[i++];
6671
int edgeValue = rawData[i++];
6772

68-
adjacencyList[edgeBeginning].push_front({edgeEnd, edgeValue});
69-
70-
if (edgeBeginning == edgeEnd)
71-
continue;
73+
if (edgeBeginning == edgeEnd) {
74+
incidenceMatrix.clear();
75+
throw "Petle sa nieakceptowane!";
76+
}
7277

78+
adjacencyList[edgeBeginning].push_front({edgeEnd, edgeValue});
7379
adjacencyList[edgeEnd].push_front({edgeBeginning, edgeValue});
7480
}
7581
}

0 commit comments

Comments
 (0)