Class Dqueue - ISC COMPUTER PROJECT 2018: Import Import Class Int Int Int
Class Dqueue - ISC COMPUTER PROJECT 2018: Import Import Class Int Int Int
1 import java.io.*;
2 import java.util.Scanner;
3
4 class Dqueue
5 {
6 int Dqueue[]=new int[5];
7 int capacity, front, rear;
8
9 public Dqueue()
10 {
11 int i;
12 for( i=0; i<=4; i++)
13 Dqueue[i]=0;
14
15 front=0; rear= -1;
16 }
17
18 public Dqueue( int nx, int nf, int nr)
19 {
20 capacity=nx; front=0; rear=-1;
21 }
22
23 public void pushFront(int num)
24 {
25 if( front==0 && rear== -1) // condition for queue empty
26 {
27 Dqueue[++rear]=num;
28 }
29 else
30 if (front==0 )
31 {
32 System.out.println("Insertion at Front not possible");
33 return;
34 }
35 else
36 if (front==0 && rear==4)
37 {
38
39 System.out.println("Dqueue overflow");
40
41 return;
42 }
43 else
44 if( front != 0)
45 {
46 Dqueue[--front]=num;
47 }
48 }
49
50 public void pushRear(int num)
51 {
52 if( rear==4 || ( front==0 && rear==4) )
53 {
54
55 System.out.println("Dqueue overflow/insertion at rear
not possible");
56
57 return;
58 }
59 else
60 Dqueue[++rear]=num;
61 }
62
63 public void display()
64 {
65 int i;
66 if( front==0 && rear== -1 )
67 {
68
69 System.out.println("Dqueue underflow");
70
71 }
72
73 for( i= front; i<=rear; i++)
74 System.out.print( Dqueue[i] + " ");
75 }
76
77 public int removeFront()
78 {
79 int value;
80 if (front > rear)
81 {
82
83 System.out.println("Dqueue underflow");
84 return -999;
85 }
86 else
87 if ( front==rear )
88 {
89
90 System.out.print("Deleted element is" );
91 value= Dqueue[front];
92 front=0; rear=-1;
93 return value;
94 }
95 else
96 {
97
98 System.out.print("Deleted element is ");
99 return Dqueue[front++];
100 }
101 }
102
103 public int removeRear()
104 {
105 int value;