You are on page 1of 5

Filenames: CCL212-18_YourSection_OLA-F3_YourLastnameFirstnameMI.

java
CCL212-18_YourSection_OLA-F3_YourLastnameFirstnameMI.pdf

Here is a sample output:


Enter the size of the Queue: 8
Menu
1. Enqueue
2. Dequeue
3. Display Queue
4. Exit
Enter Choice [1..4]

Here are the instructions:


Create user defined function for each operation
1. ENQUEUE
Insert the data to the queue if the queue is not full.
Else, display Queue Overflow.
Display the new Queue, Front index, and Rear index.

Sample Output 1:
Enter a number: 10
Queue: 10
Front: 0
Rear: 0

Sample Output 2:
Enter a number: 2
Queue: 2
Front: 0
Rear: 1

2. DEQUEUE
Remove the data in Front. Display the new Queue, Front index, and Rear index.

20 3 13 30 12 13 15
0 1 2 3 4 5 6 7

Sample Output:
Queue: 10 – 2 – 3 – 13 – 30 – 12 20
Dequeue()
Front: 1 2
Rear: 5 0
3. DISPLAY QUEUE
Display the Queue, Front and Rear
10 2 3 13 30 12
0 1 2 3 4 5 6 7

Sample Output:

Queue: 10 – 2 – 3 – 13 – 30 – 12
Front: 0
Rear: 5

4. EXIT - Display the Programmer’s Name ( LastName, Firstname MI.)

Source Code

SINGLE SPACE, FONT SIZE = 10, Courier New

package OnlineActivity;
import java.util.Deque;
import java.util.*;

public class activity3 {


static int size, front= 0, rear=0;
private static int queue[];
static Scanner sc = new Scanner (System.in);
static int choice, value;

public static void main(String[] args) {


System.out.print("Enter the size of a queue: ");
size= sc.nextInt();
while (true) {
System.out.println("\nMenu");
System.out.println("1. Enqueue"+"\n2. Dequeue"+"\n3. Display Queue"+"\n4. Exit\n");
System.out.print("Enter choice 1...4: " );
choice=sc.nextInt();
if (choice==1) {
Enqueue(value);
}
else if (choice ==2) {
Dequeue(value);
}
else if (choice ==3) {
Display();
}
else {
System.out.println("Noquiz,Erickson John F.");
break;
}
}
}
public static void Enqueue(int value) {
if (front == rear+1)
System.out.println("Queue Overflow");
else {
if (rear == size-1 && front!=0)
// TODO Auto-generated method stub

rear= -1;
System.out.print("Enter a number: ");
value=sc.nextInt();
System.out.println("Queue: " + value);
System.out.println("Front: "+ front + "\nRear: "+ rear );
}
}
public static void Dequeue(int value) {
Deque<String> deque = new LinkedList();
deque.addFirst("20");
deque.add("3");
deque.add("13");
deque.add("30");
deque.add("12");
deque.add("13");
deque.add("15");
if (front == -1) {
System.out.printf("\nQueue underflow\n");
return;
}
else {
System.out.println("Queue: " + deque);
System.out.println("After removing front " + deque.removeFirst());
System.out.println("Front: " + "1" + "\t"+deque.getFirst() +"\nRear: " + "2" +
"\t\t"+ deque.getLast());
System.out.println(" ");
}
}
public static void Display() {
Deque<String> deque = new LinkedList();
deque.addFirst("10");
deque.add("2");
deque.add("3");
deque.add("13");
deque.add("30");
deque.add("12");
System.out.println("Queue "+ deque);
System.out.println("Front "+ front+ "\nRear "+ "5");
}

}
Screenshot of the Output
Circular Queues

You might also like