We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7eea1d6 commit c698b43Copy full SHA for c698b43
DataStructures/Queues/Queues.java
@@ -130,6 +130,20 @@ public boolean isFull() {
130
public int getSize() {
131
return nItems;
132
}
133
+
134
+ @Override
135
+ public String toString() {
136
+ StringBuilder sb = new StringBuilder();
137
+ sb.append("[");
138
+ for (int i = front; ; i = ++i % maxSize) {
139
+ sb.append(queueArray[i]).append(", ");
140
+ if (i == rear) {
141
+ break;
142
+ }
143
144
+ sb.replace(sb.length() - 2, sb.length(), "]");
145
+ return sb.toString();
146
147
148
149
/**
@@ -161,5 +175,6 @@ public static void main(String args[]) {
161
175
162
176
System.out.println(myQueue.peekFront()); // Will print 2
163
177
System.out.println(myQueue.peekRear()); // Will print 7
178
+ System.out.println(myQueue.toString()); // Will print [2, 5, 3, 7]
164
179
165
180
0 commit comments