forked from TrachtmanLior/SystemProgrammingAEx2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_graph.c
53 lines (48 loc) · 1.61 KB
/
my_graph.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include "my_mat.h"
#include <stdbool.h>
int main(){
int i,j;
char operator;
int matrix[MATRIX_SIZE][MATRIX_SIZE];
bool didAlgoRun = false; // Tell us if the Floyd's algo already ran for the current matrix - so we don't run it again
bool keepGettingInput = true; // false when 'D' or EOF is inputed
bool dropLine = false; // used to drop line only before B or C new inputs
// Assuming the user enters values to matrix (A) before trying B or C
while (keepGettingInput){
scanf("%c", &operator);
if (dropLine && operator != ' ' && operator != 'D' && operator != EOF && operator != 'A'){
printf("\n");
}
switch(operator){
case 'A':
getMatrix(matrix, MATRIX_SIZE);
didAlgoRun = false;
break;
case 'B':
scanf("%d%d", &i, &j);
if (!didAlgoRun) {
floydWarshallAlgorithm(matrix, MATRIX_SIZE);
didAlgoRun = true;
}
printf("%s", existPath(matrix, i, j, MATRIX_SIZE) ? "True":"False");
dropLine = true;
break;
case 'C':
scanf("%d%d", &i, &j);
if (!didAlgoRun) {
floydWarshallAlgorithm(matrix, MATRIX_SIZE);
didAlgoRun = true;
}
printf("%d", shortestPath(matrix, i, j, MATRIX_SIZE));
dropLine = true;
break;
case EOF:
case 'D':
printf("\n");
keepGettingInput = false;
break;
}
}
return 0;
}