bully algorithm in java source code
#1

please give me the java code for bully algorithm
Reply
#2
import java.util.*;
class Bully1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=0;
while(n==0)
{
System.out.println("enter number of processes");
n=sc.nextInt();
if(n==0)
System.out.println("dude, process cannot be 0 ");
}
int pid[]=new int[n];

for(int i=0;i<n;i++)
{
pid[i]=1;
}
/*for(int k:pid)
System.out.println(k);*/
int max=Max.max(pid,0);
int cord=max;
System.out.println(":cord"+(cord));



//crash-=1;
while(true)
{
System.out.println("enter option:\n1.crash a process\n2.revoke\n3.exit");
int choice =sc.nextInt();
switch(choice)
{
case 1:
System.out.println("enter process to be crash");
int crash=sc.nextInt();
try
{
if(pid[crash]==0)
{
System.out.println("process already crashed");
}
else
{
pid[crash]=0;
System.out.println("enter the process who will initiate election");
int start=sc.nextInt();
//revoke-=1;

if(pid[start]==0)
{
System.out.println("process dead");
continue;
}
else
{

System.out.println("nold coordinator :"+cord);

cord=Max.max(pid,start);
System.out.println("new coordinator :"+cord);




}
}
}
catch(ArrayIndexOutOfBoundsException d)
{
System.out.println("does not exist"+d);
}
catch(Exception e)
{
System.out.println(e);
}

break;
case 2:
try
{
System.out.println("enter process u want to revoke");
int revoke=sc.nextInt();
if(pid[revoke]==1)
{
System.out.println("dude,process already alive");
}
else
{
pid[revoke]=1;
if(cord<revoke)
cord=revoke;
System.out.println("new coordinator is "+cord);

}
}
catch(ArrayIndexOutOfBoundsException d)
{
System.out.println("does not exist"+d);
}
catch(Exception e)
{
System.out.println(e);
}
break;
case 3:
return;
default:System.out.println("wrong choice");
break;

}
}

}



}
class Max
{
public static int max(int pid[],int k)
{
int max=0;
for(int i=k;i<pid.length;i++)
{
System.out.println("message received by process"+i);
if(pid[i]==1)
{
max=i;
}
}
return max;
}
}
Reply
#3
To get full information or details of bully algorithm in java source code please have a look on the pages

http://studentbank.in/report-bully-algor...ource-code

if you again feel trouble on bully algorithm in java source code please reply in that page and ask specific fields in bully algorithm in java source code
Reply
#4

To get full information or details of bully algorithm in java source code please have a look on the pages

http://studentbank.in/report-bully-algor...ource-code

if you again feel trouble on bully algorithm in java source code please reply in that page and ask specific fields in bully algorithm in java source code
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Tagged Pages: bully algorithm program in java, bully algorithm in java, bully election algorithm java code, java program for bully algorithm, election algorithm program in java, bully algorithm source code, bully election algorithm in java download,
Popular Searches: bully election algorithm in java source code, www givemethejava com, implementation of bully algorithm in java, bully algorithm c code for client server communication, how to treat a bully, mikrotik the dude, bully algorithm program in java,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  free download source code of online college magazine 5 17,867 29-06-2018, 10:09 AM
Last Post: Guest
  opengl source code for butterfly 3 3,275 14-05-2018, 08:57 AM
Last Post: Akshatha k
  ice cream parlour management system in vb source code 4 5,290 04-04-2018, 11:58 PM
Last Post: vprk77
  dwt code in java for image 2 6,354 24-03-2018, 10:06 PM
Last Post: Guest
  source code in php for online training and placement cell management 1 6,688 23-03-2018, 09:06 AM
Last Post: ritzi
  free download college website project in html with source code 2 4,622 24-02-2018, 10:46 AM
Last Post: Guest
  source code for hospital management system in jsp 4 1,951 13-01-2018, 10:51 AM
Last Post: dhanabhagya
  source code in c for dna cryptography in computer sc ppt 1 1,534 09-01-2018, 09:59 PM
Last Post: harshavarshinib
  to find whether a number is krishnamurthy number or not using java 1 11,262 01-01-2018, 11:39 AM
Last Post: dhanabhagya
  java programmings for bus ticket reservation source code 1 6,222 09-11-2017, 11:28 PM
Last Post: Ayushi Nagar

Forum Jump: