bully algorithm in java source code
#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

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: election java program using bully algorithm, to study bully algorithm with java program, java code for bully algorithm, www givemethejava com, bully election algorithm program in java, bully algorithm in java, program of buuly algorithm,
Popular Searches: bully algorithm in java rmi, bully election algorithm code in c, election java program using bully algorithm, bully algorithm program in java, bully algorithm c code for client server communication, java code for bully algorithm implementation, bully algorithm in java source code,

[-]
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)

Messages In This Thread
bully algorithm in java source code - by Guest - 20-03-2013, 11:32 AM
RE: bully algorithm in java source code - by Guest - 25-04-2015, 12:11 AM

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

Forum Jump: