TO IMPLEMENT FIFO-First In First Out
*/
import java.util.*;
class Queue
{
int q[]=new int[3];
int f=0;
int count=0;
void insert(int d)
{
if(f!=3)
{
if(q[f]==d && count==2)
{System.out.print("\nHIT");}
else
q[f++]=d;
}
else
{
f=0;
if(q[f]==d && count==2)
{System.out.print("\nHIT");}
else
q[f++]=d;
}
}
void traverse()
{
for(int i=0;i<=count;i++)
{
System.out.print("\n"+q[i]);
}
if(count<2) count++;
System.out.println();
}
}
class FIFO
{
public static void main(String args[])
{
Scanner src=new Scanner(System.in);
int a[]={7,0,1,2,0,3,0,4,2,3,0,3,2,1};
Queue q=new Queue();
for(int i=0;i<14;i++)
{
q.insert(a[i]);
q.traverse();
}
}
}
/*OUTPUT
bash-3.00$ java FIFO
7
7
0
7
0
1
2
0
1
HIT
2
0
1
2
3
1
2
3
0
4
3
0
4
2
0
4
2
3
0
2
3
0
3
3
0
3
2
1
3
2
*/
No comments:
Post a Comment