Queue using Java Collections Framework

Queue is implemented in Java using the Collections Framework. It helps us in doing the actual work rather than making the primitive stack functions again and again.  Queue follows FIRST IN FIRST OUT operation.

/*
OUTPUT
run:

Queue contains->[]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

2
Queue already empty!UNDERFLOW!

Queue contains->[]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

1
Enter item to insert:
58

Queue contains->[58]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

22
Wrong choice try again!

Queue contains->[58]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

1
Enter item to insert:
58

Queue contains->[58, 58]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

1
Enter item to insert:
69

Queue contains->[58, 58, 69]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

1
Enter item to insert:
74

Queue contains->[58, 58, 69, 74]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

2
Element deleted->58

Queue contains->[58, 69, 74]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

2
Element deleted->58

Queue contains->[69, 74]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

2
Element deleted->69

Queue contains->[74]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

1
Enter item to insert:
14

Queue contains->[74, 14]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

2
Element deleted->74

Queue contains->[14]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

2
Element deleted->14

Queue contains->[]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

2
Queue already empty!UNDERFLOW!

Queue contains->[]
Enter choice:
1.INSERT
2.DELETE
0.EXIT

0
BYE BYE!!
*/

Leave a Reply

%d bloggers like this: