我是数据结构的新手。在参考了很多书之后,我已经完成了线性队列的实现。
这是我对线性队列的实现。
public class QueueObject {
private Object[] heads;
private int rearPointer, frontPointer, currentNumber;
public QueueObject(int capacity) {
heads = new Object[capacity];
}
public boolean isEmpty(){
return (currentNumber == 0);
}
public boolean isFull(){
return (currentNumber == heads.length);
}
public void push(Object o){
if(isFull()){
return;
}
// means we are at last position (deal with wrap around)
if(rearPointer >= heads.length){
rearPointer = 0;
}
heads[rearPointer++] = o;
currentNumber++;
}
public Object pop(){
if(isEmpty()){
return null;
}
// dealing with wrap around
if(frontPointer >= heads.length){
frontPointer = 0;
}
Object o = heads[frontPointer++];
currentNumber--;
return o;
}
}
现在我的问题是处理环绕使它成为循环队列而不是线性队列吗?
答案 0 :(得分:1)
是的,它是一个环形缓冲区。
循环队列是一种线性数据结构,其中操作基于FIFO(先进先出)原理执行,最后一个位置连接回第一个位置以形成圆。
查看有关http://btechsmartclass.com/DS/U2_T10.html和https://www.quora.com/What-are-the-applications-of-circular-queues-in-C
的详细说明