MCPcopy Create free account
hub / github.com/Deepali-Srivastava/data-structures-and-algorithms-in-java / DequeA

Class DequeA

queue/deque/DequeA.java:10–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import java.util.NoSuchElementException;
9
10public class DequeA
11{
12 private int[] queueArray;
13 private int front;
14 private int rear;
15
16 public DequeA()
17 {
18 queueArray = new int[10];
19 front = -1;
20 rear = -1;
21 }
22 public DequeA(int maxSize)
23 {
24 queueArray = new int[maxSize];
25 front = -1;
26 rear = -1;
27 }
28 public void insertFront(int x)
29 {
30 if(isFull())
31 {
32 System.out.println("Queue Overflow");
33 return;
34 }
35 if(front==-1)
36 {
37 front=0;
38 rear=0;
39 }
40 else if(front==0)
41 front=queueArray.length-1;
42 else
43 front=front-1;
44 queueArray[front]=x;
45 }
46
47 public void insertRear(int x)
48 {
49 if(isFull())
50 {
51 System.out.println("Queue Overflow");
52 return;
53 }
54 if(front==-1)
55 front=0;
56
57 if(rear==queueArray.length-1)
58 rear=0;
59 else
60 rear=rear+1;
61 queueArray[rear]=x;
62 }
63
64 public int deleteFront()
65 {
66 int x;
67 if( isEmpty() )

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected