forked from hussien89aa/DataStructureAndAlgorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueArray.java
More file actions
40 lines (38 loc) · 686 Bytes
/
QueueArray.java
File metadata and controls
40 lines (38 loc) · 686 Bytes
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
package com.ds;
public class QueueArray<T> {
Object[] ArrayQueue;
int Rear;
int Front;
int size;
public QueueArray(int size) {
this.size=size;
ArrayQueue= new Object[this.size];
Front=-1;
Rear=-1;
}
public Boolean isFull(){
return(Rear==size-1);
}
public Boolean isEmplty(){
return(Front==-1|| Front>Rear);
}
public void Queue(Object newItem){
if(isFull()){
System.out.println("queue is full");
return;
}
Rear=Rear+1;
ArrayQueue[Rear]= newItem;
if(Front==-1)
Front=0;
}
public T DeQueue(){
if(isEmplty()){
System.out.println("queue is empty");
return null;
}
T ObjectOut=(T) ArrayQueue[Front];
Front=Front+1;
return ObjectOut;
}
}