-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.java
More file actions
61 lines (60 loc) · 1.13 KB
/
queue.java
File metadata and controls
61 lines (60 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
public class queue {
int num[] ;
int i;
int top;
int maxSize;
public queue(int length)
{
this.maxSize=length;
top=-1;
num=new int [maxSize];
}
public boolean isEmpty()
{
return top==-1;
}
public boolean isFull()
{
return top==maxSize-1;
}
public void push(int newElm)
{
if(!isFull()) {
num[++top] = newElm;
}
else
{
System.out.println("array is full");
}
}
public void pop()
{
for(i=0;i<top;i++) {
num[i]=num[i+1];
}
top--;
}
public void print() {
if(isEmpty())
{
System.out.println("array is Empty");
}
else {
System.out.println("numbers are:");
for (i = 0; i <= top; i++) {
System.out.print(num[i] + " ");
}
}
}
public static void main(String a [])
{
queue q=new queue(5);
q.push(51);
q.push(56);
q.push(56);
q.pop();
q.push(566);
q.pop();
q.print();
}
}