Skip to content

Commit 9534874

Browse files
committed
Update test results
1 parent 0cab126 commit 9534874

File tree

4 files changed

+72
-29
lines changed

4 files changed

+72
-29
lines changed

src/main/java/org/alda/Main.java

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -210,31 +210,39 @@ public static void testDoublyLinkedList() {
210210
}
211211

212212
public static void testCircularLinkedList() {
213+
System.out.println("\n=== Initialize Circular Linked List ===");
213214
CircularLinkedList<Integer> intList = new CircularLinkedList<Integer>();
214215

216+
System.out.println("Actions: \nAppend 2, 3, 4, 5");
215217
intList.append(2);
216218
intList.append(3);
217219
intList.append(4);
218220
intList.append(5);
219221

222+
System.out.print("\nPrint List (Forward):");
220223
intList.print();
221224
}
222225

223226
public static void testSortedLinkedList() {
227+
System.out.println("\n=== Initialize Sorted Linked List ===");
224228
ISortedLinkedList<Integer> intList = new SortedLinkedList<Integer>();
225229

230+
System.out.println("Actions: \nSorted Insert 10, 50, 30, 70, 20");
226231
intList.sortedInsert(10);
227232
intList.sortedInsert(50);
228233
intList.sortedInsert(30);
229234
intList.sortedInsert(70);
230235
intList.sortedInsert(20);
231236

237+
System.out.print("\nPrint List (Forward):");
232238
intList.print();
233239
}
234240

235241
public static void testDoublyEndedList(){
242+
System.out.println("\n=== Initialize Doubly Ended Linked List ===");
236243
IDoublyEndedList<Integer> intList = new DoublyEndedList<>();
237244

245+
System.out.println("Actions: \nAppend 1, 2, 3, 4, 5, 6, 7");
238246
intList.appendEnd(1);
239247
intList.appendEnd(2);
240248
intList.appendFront(3);
@@ -243,36 +251,43 @@ public static void testDoublyEndedList(){
243251
intList.appendFront(6);
244252
intList.appendEnd(7);
245253

254+
System.out.print("\nPrint List (Forward):");
246255
intList.print();
247256
}
248257

249258
public static void testStackArray(){
259+
System.out.println("\n=== Initialize Stack Array ===");
250260
IStackArray<Integer> intStack = new StackArray<>();
251261

262+
System.out.println("Actions: \nPush 1, 2, 3");
252263
intStack.push(1);
253264
intStack.push(2);
254265
intStack.push(3);
255266

256-
System.out.println(intStack.pop());
257-
System.out.println(intStack.peek());
258-
System.out.println(intStack.pop());
267+
System.out.println("\nPop: " + intStack.pop());
268+
System.out.println("Peek: " + intStack.peek());
269+
System.out.println("Pop: " + intStack.pop());
259270
}
260271

261272
public static void testStackLinkedList(){
273+
System.out.println("\n=== Initialize Stack Linked List ===");
262274
IStackLinkedList<Integer> intStack = new StackLinkedList<>();
263275

276+
System.out.println("Actions: \nPush 1, 2, 3");
264277
intStack.push(1);
265278
intStack.push(2);
266279
intStack.push(3);
267280

268-
System.out.println(intStack.pop());
269-
System.out.println(intStack.peek());
270-
System.out.println(intStack.pop());
281+
System.out.println("\nPop: " + intStack.pop());
282+
System.out.println("Peek: " + intStack.peek());
283+
System.out.println("Pop: " + intStack.pop());
271284
}
272285

273286
public static void testQueue(){
287+
System.out.println("\n=== Initialize Queue ===");
274288
IQueue<Integer> intQueue = new Queue<>();
275289

290+
System.out.println("Actions: \nEnqueue 1, 2, 3, 4, 5");
276291
intQueue.enqueue(1);
277292
intQueue.enqueue(2);
278293
intQueue.enqueue(3);
@@ -286,16 +301,18 @@ public static void testQueue(){
286301
Integer front = intQueue.front();
287302
Integer rear = intQueue.rear();
288303

289-
System.out.println(item);
290-
System.out.println(item1);
291-
System.out.println(item2);
292-
System.out.println(front);
293-
System.out.println(rear);
304+
System.out.println("\nDequeue: " + item);
305+
System.out.println("Dequeue: " + item1);
306+
System.out.println("Dequeue: " + item2);
307+
System.out.println("Front: " + front);
308+
System.out.println("Rear: " + rear);
294309
}
295310

296311
public static void testQueueArray(){
312+
System.out.println("\n=== Initialize Queue Array ===");
297313
IQueue<Integer> intQueue = new QueueArray<>();
298314

315+
System.out.println("Actions: \nEnqueue 1, 2, 3, 4, 5");
299316
intQueue.enqueue(1);
300317
intQueue.enqueue(2);
301318
intQueue.enqueue(3);
@@ -309,16 +326,18 @@ public static void testQueueArray(){
309326
Integer front = intQueue.front();
310327
Integer rear = intQueue.rear();
311328

312-
System.out.println(item);
313-
System.out.println(item1);
314-
System.out.println(item2);
315-
System.out.println(front);
316-
System.out.println(rear);
329+
System.out.println("\nDequeue: " + item);
330+
System.out.println("Dequeue: " + item1);
331+
System.out.println("Dequeue: " + item2);
332+
System.out.println("Front: " + front);
333+
System.out.println("Rear: " + rear);
317334
}
318335

319336
public static void testQueueLinkedList(){
337+
System.out.println("\n=== Initialize Queue Linked List ===");
320338
IQueue<Integer> intQueue = new QueueLinkedList<>();
321339

340+
System.out.println("Actions: \nEnqueue 1, 2, 3, 4, 5");
322341
intQueue.enqueue(1);
323342
intQueue.enqueue(2);
324343
intQueue.enqueue(3);
@@ -332,45 +351,59 @@ public static void testQueueLinkedList(){
332351
Integer front = intQueue.front();
333352
Integer rear = intQueue.rear();
334353

335-
System.out.println(item);
336-
System.out.println(item1);
337-
System.out.println(item2);
338-
System.out.println(front);
339-
System.out.println(rear);
354+
System.out.println("\nDequeue: " + item);
355+
System.out.println("Dequeue: " + item1);
356+
System.out.println("Dequeue: " + item2);
357+
System.out.println("Front: " + front);
358+
System.out.println("Rear: " + rear);
340359
}
341360

342361
public static void testPriorityQueue(){
362+
System.out.println("\n=== Initialize Priority Queue ===");
343363
IPriorityQueue<Integer> intQueue = new PriorityQueue<>();
344364

365+
System.out.println("Actions: \n- Enqueue 2 with priority 1");
345366
intQueue.enqueue(2, 1);
367+
System.out.println("- Enqueue 32 with priority 25");
346368
intQueue.enqueue(32, 25);
369+
System.out.println("- Enqueue 48 with priority 0");
347370
intQueue.enqueue(48, 0);
371+
System.out.println("- Enqueue 15 with priority 3");
348372
intQueue.enqueue(15, 3);
373+
System.out.println("- Enqueue 36 with priority 2");
349374
intQueue.enqueue(36, 2);
375+
System.out.println("- Enqueue 27 with priority 4");
350376
intQueue.enqueue(27, 4);
351377

352378
Integer item = intQueue.dequeue();
353379
Integer item1 = intQueue.dequeue();
354380
Integer item2 = intQueue.dequeue();
355381
Integer item3 = intQueue.dequeue();
356382

357-
System.out.println(item);
358-
System.out.println(item1);
359-
System.out.println(item2);
360-
System.out.println(item3);
383+
System.out.println("\nDequeue: " + item);
384+
System.out.println("Dequeue: " + item1);
385+
System.out.println("Dequeue: " + item2);
386+
System.out.println("Dequeue: " + item3);
361387
}
362388

363389
public static void testBST(){
390+
System.out.println("\n=== Initialize Binary Search Tree ===");
364391
BinarySearchTree<Integer> bst = new BinarySearchTree<>();
392+
393+
System.out.println("Actions: \n- Insert 5, 3, 7, 1, 20, 4");
365394
bst.insert(5);
366395
bst.insert(3);
367396
bst.insert(7);
368397
bst.insert(1);
369398
bst.insert(20);
370399
bst.insert(4);
371400

401+
System.out.println("- Inorder Traversal ");
372402
System.out.println(bst.inorderTraversal());
373-
System.out.println(bst.search(4));
403+
System.out.print("\nSearch for 4: ");
404+
org.alda.structure.tree.bst.Node<Integer> node = bst.search(4);
405+
if (node != null) System.out.println("true");
406+
else System.out.println("false");
374407
}
375408

376409
public static void testAVL(){

src/main/java/org/alda/structure/linkedList/circular/CircularLinkedList.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public void print() {
7070
Node<T> current = head;
7171
while (current != null) {
7272
current.print();
73-
System.out.println("\n");
7473
current = current.next;
7574
if(current == head) {
7675
break;

src/main/java/org/alda/structure/linkedList/deque/DoublyEndedList.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public void print() {
7575
Node<T> current = head;
7676
while (current != null) {
7777
current.print();
78-
System.out.println("\n");
7978
current = current.next;
8079
}
8180
}
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.alda.structure.tree.bst;
22

3+
import org.alda.common.Printable;
4+
35
/**
46
* Node for binary search tree
57
* @param <T>
68
*/
7-
public class Node<T> {
9+
public class Node<T> implements Printable {
810
T key;
911
Node<T> left;
1012
Node<T> right;
@@ -13,4 +15,14 @@ public Node(T key){
1315
left = null;
1416
right = null;
1517
}
18+
19+
public void print() {
20+
System.out.print("\nData: " + key);
21+
if (left != null) {
22+
System.out.print(", Left: " + left.key);
23+
}
24+
if (right != null) {
25+
System.out.print(", Right: " + right.key);
26+
}
27+
}
1628
}

0 commit comments

Comments
 (0)