Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged

Sp7 #205

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions 36 Chapter8/Try_This_8_1.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FixedQueue implements ICharQ{

public FixedQueue(int size) {
q = new char[size]; // allocate memory for queue.

putloc = getloc = 0;
}

Expand Down Expand Up @@ -112,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;
}


Expand Down Expand Up @@ -180,20 +181,43 @@ public static void main(String[] args) {
System.out.print(ch);
}


System.out.println();

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));
}

// 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 = 10; 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);
}

}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.