From e3e15dc2973ba99e7865057fad34fb56201d6bdf Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:08:31 +0800 Subject: [PATCH 1/4] Committed on or around 2023/10/04 --- Chapter8/Try_This_8_1.java | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Chapter8/Try_This_8_1.java b/Chapter8/Try_This_8_1.java index 3528fe2..735ce48 100644 --- a/Chapter8/Try_This_8_1.java +++ b/Chapter8/Try_This_8_1.java @@ -18,7 +18,8 @@ class FixedQueue implements ICharQ{ public FixedQueue(int size) { q = new char[size]; // allocate memory for queue. - putloc = getloc = 0; + +putloc = getloc = 0; } public void put(char ch) { @@ -180,7 +181,6 @@ public static void main(String[] args) { System.out.print(ch); } - System.out.println(); iQ = q3; @@ -193,7 +193,31 @@ public static void main(String[] args) { // Show the queue. System.out.print("Contents of circular queue: "); for (i = 0; i < 10; i++) { - + ch = iQ.get(); + System.out.print(ch); + } + + System.out.println(); + + // Put more characters into circular queue. + for (i = 0; i < 20; i++) { + iQ.put((char) ('A' + i)); + } + + // Show the queue. + System.out.print("Contents of circular queue: "); + for (i = 0; i < 10; i++) { + ch = iQ.get(); + System.out.print(ch); + } + + System.out.println("\nStore and consume from" + " circular queue."); + + // Store in and consume from circular queue. + for (i = 0; i < 20; i++) { + iQ.put((char) ('A' + i)); + ch = iQ.get(); + System.out.print(ch); } } From 30e0870af28223fa624de4e8e7b6aa1953c744b9 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:30:24 +0800 Subject: [PATCH 2/4] Committed on or around 2023/10/04 --- Chapter8/Try_This_8_1.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Chapter8/Try_This_8_1.java b/Chapter8/Try_This_8_1.java index 735ce48..b3194e5 100644 --- a/Chapter8/Try_This_8_1.java +++ b/Chapter8/Try_This_8_1.java @@ -113,12 +113,12 @@ public void put(char ch) { for (int i = 0; i < q.length; i++) { t[i] = q[i]; - - q = t; } - q[putloc++] = ch; + + q = t; } + q[putloc++] = ch; } From 14325f9bcfaa3f113bb40e5647b215a4c281ef66 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:02:19 +0800 Subject: [PATCH 3/4] Committed on or around 2023/10/04 --- Chapter8/Try_This_8_1.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter8/Try_This_8_1.java b/Chapter8/Try_This_8_1.java index b3194e5..a892e59 100644 --- a/Chapter8/Try_This_8_1.java +++ b/Chapter8/Try_This_8_1.java @@ -19,7 +19,7 @@ class FixedQueue implements ICharQ{ public FixedQueue(int size) { q = new char[size]; // allocate memory for queue. -putloc = getloc = 0; + putloc = getloc = 0; } public void put(char ch) { From 1165d4bdd74eb652a72ae037fee612c4e79b1ae1 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:15:01 +0800 Subject: [PATCH 4/4] Committed on or around 2023/10/04 --- Chapter8/Try_This_8_1.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Chapter8/Try_This_8_1.java b/Chapter8/Try_This_8_1.java index a892e59..542eb47 100644 --- a/Chapter8/Try_This_8_1.java +++ b/Chapter8/Try_This_8_1.java @@ -186,7 +186,7 @@ public static void main(String[] args) { iQ = q3; // Put some characters into circular queue. - for (i = 0; i < 20; i++) { + for (i = 0; i < 10; i++) { iQ.put((char) ('A' + i)); } @@ -200,7 +200,7 @@ public static void main(String[] args) { System.out.println(); // Put more characters into circular queue. - for (i = 0; i < 20; i++) { + for (i = 10; i < 20; i++) { iQ.put((char) ('A' + i)); }