package queue;
//定义队列接口
public interface CharQueueInterface {
final int maxSize = 100;
public void initQueue();
public void push(char x);
public char pop();
public boolean fill();
}
package queue;
public class CharQueue implements CharQueueInterface{
int right;
int left;
char data[];
public CharQueue() {
data = new char[maxSize];
}
public void initQueue() {
left = right = -1;
}
public void push(char x) {
if(!fill())
{
right++;
data[right] = x;
}
}
public char pop() {
if(left<=right)
{
left++;
return data[left];
}else
{
return '/0';
}
}
public boolean fill() {
if(right == (maxSize-1))
{
return true;
}else
{
return false;
}
}
}
package queue;
public class Test {
public static void main(String[] args) {
CharQueue cq = new CharQueue();
cq.initQueue();
cq.push('A');
cq.push('B');
cq.push('C');
cq.push('D');
cq.push('E');
cq.push('F');
System.out.println(cq.pop());
System.out.println(cq.pop());
System.out.println(cq.pop());
System.out.println(cq.pop());
System.out.println(cq.pop());
System.out.println(cq.pop());
}
}