队列课下作业
作业内容
- 1 补充课上没有完成的作业
- 2 参考15.3节,用自己完成的队列(链队,循环数组队列)实现模拟票务柜台排队功能
- 3 用JDB或IDEA单步跟踪排队情况,画出队列变化图,包含自己的学号信息
- 4 把代码推送到代码托管平台
- 5 把完成过程写一篇博客:重点是单步跟踪过程和遇到的问题及解决过程
LinkedQueue代码
package ch15;
/**
* Created by 47963 on 2017/10/18.
*/
public class LinkedQueue<T> {
private int count;
private LinearNode<T> front,rear;
public LinkedQueue(){
count =0;
front = rear = null;
}
public void enqueue(T element) {
LinearNode<T> node = new LinearNode<T>(element);
if(count == 0){
front = node;
}else {
rear.setNext(node);
}
rear = node;
count++;
}
public T dequeue() throws EmptyCollectionException {
T a= front.getElement();
if(count == 0){
System.out.println("The queue is null.");
rear=front=null;
}else {
front = front.getNext();
}
count--;
return a;
}
public T first() {
T A = front.getElement();
return A;
}
public boolean isEmpty() {
boolean result=false;
if (count==0){
result=true;
}return result;
}
public int size() {
return count;
}
/* public String toString(){}*/
}
TicketCounter运行结果截图
TicketCounter Debug截图