-
Notifications
You must be signed in to change notification settings - Fork 4
/
Bully.java
58 lines (55 loc) · 1.37 KB
/
Bully.java
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
import java.util.*;
import java.util.*;
class Bully
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of processes(starting with 0): ");
int p;
p=sc.nextInt();
int a[]=new int[p+1];
System.out.println("Enter the process number which fails: ");
int f;
f=sc.nextInt();
int i;
for(i=0;i<=p;i++)
{
if (i!=f)
{
a[i]=1;
}
else
{
a[i]=0;
}
}
System.out.println("Enter the process which starts election: ");
int e;
e=sc.nextInt();
while(e<=p)
{
if(e==f)
{
e=e+1;
continue;
}
for(i=0;i<=p;i++)
{
if(e<i && (e!=f || e>f))
{
System.out.println("Election message is sent from "+e+ "to" +i);
}
}
e=e+1;
for(i=0;i<=p;i++)
{
if((e<i)&&(i!=f))
{
System.out.println("OK message is sent from "+i+"to"+e);
}
}
}
System.out.println((e-2)+" is the coordinator");
}
}