Sie sind auf Seite 1von 3

public class DoubleQueu {

int queu [];


String queu1 [];
int count ;
int rear ;
int rear1;
int front ;
int front1;
public DoubleQueu (int size ){
queu = new int[size];
queu1 = new String [size];
count = 0;
rear = 0;
front =0;
rear1 =0;
front1=0;
//queu1[rear1]=null;
}
public void enque (int data , String status){
int round = 0;
while (queu1[rear1] != null && round != queu.length )
{
if (rear != queu.length && count != queu.length )
{
rear ++;
rear1 ++;
round++;
}
else if (rear == queu.length && count != queu.length )
{
rear =0;
rear1=0;
round++;
}
}
if (round != queu.length){
queu[rear]=data;
queu1[rear1]=status;
count ++;
rear++;
rear1++;
}else{
System.out.println("queu in not empty");
}
}
public int dequeu (){
int data = 0;
int round=0;
String high = "high";
while (queu1[front1] !=high && round != queu.length)
{
if (front != queu.length ){
round ++ ;
front++;
front1++;
}
else {
if (front == queu.length ){
round++;
front ++;
front1++;
}
}
}

if (round != queu.length){
data=queu[front];
queu[front]=0;
queu1[front1]=null;
front++;
front1++;
count--;
}
else{
System.out.println("queu not contain any high priority ");
}
return data;
}
public static void main (String [] args){
DoubleQueu obj=new DoubleQueu (6);
try{
obj.enque(45, "normal");
obj.enque(78,"low" );
obj.enque(48,"high" );
obj.enque(78,"low" );
System.out.println("the value of the queu is "+ obj.queu[0] +" status i
s "+ obj.queu1[0] );
System.out.println("the value of the queu is "+ obj.queu[1]+" status is
"+ obj.queu1[1]);
System.out.println("the value of the queu is "+ obj.queu[3]+" status is
"+ obj.queu1[3]);
obj.enque(78,"normal" );
obj.enque(88,"low" );
int data =obj.dequeu();
System.out.println ("the deletion value is =" + data);
obj.enque(98,"low" );
}catch(ArrayIndexOutOfBoundsException ex ){
System.out.println("exception occured "+ex.getMessage());
}
System.out.println("the value of the queu is "+ obj.queu[4]+" status is
"+ obj.queu1[4]);
System.out.println("the value of the queu is "+ obj.queu[5]+" status is
"+ obj.queu1[5]);
System.out.println("the value of the queu is "+ obj.queu[2]+" status is
"+ obj.queu1[2]);
}
}

Das könnte Ihnen auch gefallen