活动内容:

  • 1 参考程序15.6给出方法deque,first,isEmpty,size,toString的定义,完成CireclularArrayQueue类并用Junit进行单元测试(正常,异常,边界情况)
  • 2 提交测试代码运行截图,要全屏,包含自己的学号信息
  • 3课下把代码推送到代码托管平台

实现过程:

  • 首先我们把15.6的代码敲出来。
  • 然后我们开始实现里面的方法。
  • size方法只要返回count
  • first类似于数组的peek方法,所以我复制了一下
  • isEmpty方法直接复制数组的isEmpty方法
  • toString方法需要稍做修改
String result = "<top of stack>\n";
        for (int index = count - 1; index >= 0; index--)
            result += stack[index] + "\n";
        return result + "<bottom of stack>";

这是我ArrayStack中toString方法的代码。

String result = "";
        for (int index = count - 1; index >= 0; index--)
            result += queue[index] +" ";
        return result ;
  • 这是Queue中的代码。为什么我把"<top of stack>\n" "<bottom of stack>"改成了""和删除了呢。因为在Junit测试中,要给出期望值。但是如果我用ArrayStack的代码做测试会出现这种情况
    那么哪里出来问题呢,我们用main函数运行一下看看(图片)找到问题在哪了,我们要把字符串改成空格,不过我还是不太理解,所以会去找一下助教或者是老师。
  • dequeue方法。

码云链接

实现图片

{{uploading-image-86119.png(uploading...)}}

posted on 2017-10-18 22:23  20162319莫礼钟  阅读(146)  评论(0编辑  收藏  举报