队列课下作业

队列课下作业

要求

1 补充课上没有完成的作业
2 参考15.3节,用自己完成的队列(链队,循环数组队列)实现模拟票务柜台排队功能
3 用JDB或IDEA单步跟踪排队情况,画出队列变化图,包含自己的学号信息
4 把代码推送到代码托管平台
5 把完成过程写一篇博客:重点是单步跟踪过程和遇到的问题及解决过程
6 提交博客链接

课堂代码实现

package javafoundations;
import javafoundations.exceptions.*;

public class LinkedQueue implements QueueADT
{
private int count;
private LinearNode front, rear;

public LinkedQueue()
{
    count = 0;
    front = rear = null;
}


public void enqueue (T element)
{
    LinearNode<T> node = new LinearNode<T>(element);

    if (isEmpty())
        front = node;
    else
        rear.setNext (node);

    rear = node;
    count++;
}


public T dequeue() throws EmptyCollectionException
{
    if (isEmpty())
        throw new EmptyCollectionException ("queue");

    T result = front.getElement();
    front = front.getNext();
    count--;

    if (isEmpty())
        rear = null;

    return result;
}


public T first() throws EmptyCollectionException
{
    if (isEmpty())
        throw new EmptyCollectionException ("queue");

    return front.getElement();
}


public boolean isEmpty()
{
    return (count == 0);
}


public int size()
{
    return count;
}


public String toString()
{
    String result = "";
    LinearNode<T> current = front;

    while (current != null)
    {
        result = result + (current.getElement()).toString() + "\n";
        current = current.getNext();
    }

    return result;
}

}

实现课本代码截图与Debug截图

image
image

关于队列

处理一个人需要120秒,15秒来一个顾客,一个队伍,先来后到,总共会来100名顾客。
只有一个售票员:120/15=8个 处理一个人的时候,会有8个人在排队,100/8=12.5,即处理第13个顾客时,100个客人到齐了,由此来推算,如果想要实现顾客无排队情况的话,八个售票员才可以办到。而买票总时间不超过7分钟(420秒),根据代码实现截图来看,应该是6个雇员355秒才是最佳选项。
用坐标轴来看X轴为雇员的数量Y轴为所需时间来看,我觉得应该是一个这样的图
image

posted @ 2017-10-22 17:34  DeforeSya  阅读(165)  评论(0编辑  收藏  举报