Lets Create Our Own Custom Queue.
package sorting;
public class UQueue {
private Object[] q;
private int size;
private int total;
private int front;
private int rear;
public UQueue() {
size = 100;
total = 0;
front = 0;
rear = 0;
q = new Object[size];
}
public UQueue(int size) {
total = 0;
front = 0;
rear = 0;
q = new Object[size];
}
public boolean enqueue(Object item) {
if (isFull()) {
return false;
} else {
total++; // total will contain total number of arrary size
q[rear] = item;
rear++;
return true;
}
}
public Object dequeue() {
Object item = q[front];
total--;
front++;
return item;
}
public boolean isFull() {
return size == total;
}
}
Comments
Post a Comment