ACN Mod-Congestion control w/o timer

import java.io.*;
import java.lang.*;
import java.util.*;

class Control
{
public static void main(String args[])
{
int node,noc,i,sum=0,j,temp;
Scanner sc=new Scanner(System.in);

System.out.println(“Enter the no of connections : “);
noc=sc.nextInt();

int con[]=new int[noc];
int pr[]=new int[noc];
boolean acc[]=new boolean[noc];

System.out.println(“Enter the size of the node : “);
node=sc.nextInt();

System.out.println(“Enter the size and type of each connection(1 for cbr,2 for vbr,3 for ubr,4 for abr) : “);

for(i=0;i<noc;i++)
{
con[i]=sc.nextInt();
pr[i]=sc.nextInt();
}

for(i=0;i<noc-1;i++)
{
for(j=0;j<noc-1-i;j++)
{
if(pr[j]>pr[j+1])
{
temp=pr[j];
pr[j]=pr[j+1];
pr[j+1]=temp;

temp=con[j];
con[j]=con[j+1];
con[j+1]=temp;
}
}
}

i=0;
while(node>0 && i<noc)
{
if ((node-con[i])>=0)
{
node=node-con[i];
acc[i]=true;
System.out.println(“Connection “+(i+1)+” accepted.”);
}
i++;
}

for (i=0;i<noc;i++)
if(!acc[i])
System.out.println(“Connection “+(i+1)+” rejected.”);
}
}

Advertisement

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.