diff --git a/java/09_queue/CircularQueue.java b/java/09_queue/CircularQueue.java index c3c54cc..71a988c 100644 --- a/java/09_queue/CircularQueue.java +++ b/java/09_queue/CircularQueue.java @@ -36,7 +36,8 @@ public class CircularQueue { } public void printAll() { - for (int i = head; i < tail; ++i) { + if (0 == n) return; + for (int i = head; i % n != tail; ++i) { System.out.print(items[i] + " "); } System.out.println(); diff --git a/java/09_queue/DynimacArrayQueue.java b/java/09_queue/DynamicArrayQueue.java similarity index 94% rename from java/09_queue/DynimacArrayQueue.java rename to java/09_queue/DynamicArrayQueue.java index 3a19fa3..9faad0f 100644 --- a/java/09_queue/DynimacArrayQueue.java +++ b/java/09_queue/DynamicArrayQueue.java @@ -3,7 +3,7 @@ package queue; /** * Created by wangzheng on 2018/10/9. */ -public class DynimacArrayQueue { +public class DynamicArrayQueue { // 数组:items,数组大小:n private String[] items; private int n = 0; @@ -12,7 +12,7 @@ public class DynimacArrayQueue { private int tail = 0; // 申请一个大小为capacity的数组 - public DynimacArrayQueue(int capacity) { + public DynamicArrayQueue(int capacity) { items = new String[capacity]; n = capacity; }