-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVector_Clock.cpp
62 lines (53 loc) · 1.37 KB
/
Vector_Clock.cpp
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
54
55
56
57
58
59
60
61
62
#include<bits/stdc++.h>
using namespace std;
int max1(int a, int b) {
if (a > b)
return a;
else
return b;
}
int main() {
int i, j, k, p1[20], p2[20], e1, e2, dep[20][20];
printf("enter the events : ");
scanf("%d %d", & e1, & e2);
int vector1[e1][2], vector2[e2][2];
for (i = 0; i < e1; i++) {
vector1[i][0] = i + 1;
vector1[i][1] = 0;
}
for (i = 0; i < e2; i++) {
vector2[i][1] = i + 1;
vector2[i][0] = 0;
}
printf("enter the dependency matrix:\n");
printf("\t enter 1 if e1->e2 \n\t enter -1, if e2->e1 \n\t else enter 0 \n\n");
for (i = 0; i < e2; i++)
printf("\te2%d", i + 1);
for (i = 0; i < e1; i++) {
printf("\n e1%d \t", i + 1);
for (j = 0; j < e2; j++)
scanf("%d", & dep[i][j]);
}
for (i = 0; i < e1; i++) {
for (j = 0; j < e2; j++) {
if (dep[i][j] == 1) {
vector2[j][0] = vector1[i][0];
for (k = j; k < e2; k++)
vector2[k + 1][0] = vector2[j][0];
}
if (dep[i][j] == -1) {
vector1[i][1] = vector2[j][1];
for (k = i; k < e1; k++)
vector1[k + 1][1] = vector1[i][1];
}
}
}
printf("\nProcess 1 : ");
for (i = 0; i < e1; i++)
printf("%d %d --> ", vector1[i][0], vector1[i][1]);
printf("\nProcess 2 : ");
for (j = 0; j < e2; j++)
printf("%d %d --> ", vector2[j][0], vector2[j][1]);
cout << endl;
return 0;
}