File tree 1 file changed +20
-1
lines changed
1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -271,6 +271,18 @@ public void display() { // Prints contents of the list
271
271
}
272
272
System .out .println ();
273
273
}
274
+
275
+ /**
276
+ * Prints the contents of the list in reverse order
277
+ */
278
+ public void displayBackwards () {
279
+ Link current = tail ;
280
+ while (current != null ) {
281
+ current .displayLink ();
282
+ current = current .previous ;
283
+ }
284
+ System .out .println ();
285
+ }
274
286
}
275
287
276
288
/**
@@ -311,28 +323,35 @@ public static void main(String args[]) {
311
323
myList .insertHead (7 );
312
324
myList .insertHead (10 );
313
325
myList .display (); // <-- 10(head) <--> 7 <--> 13(tail) -->
326
+ myList .displayBackwards ();
314
327
315
328
myList .insertTail (11 );
316
329
myList .display (); // <-- 10(head) <--> 7 <--> 13 <--> 11(tail) -->
330
+ myList .displayBackwards ();
317
331
318
332
myList .deleteTail ();
319
333
myList .display (); // <-- 10(head) <--> 7 <--> 13(tail) -->
334
+ myList .displayBackwards ();
320
335
321
336
myList .delete (7 );
322
337
myList .display (); // <-- 10(head) <--> 13(tail) -->
338
+ myList .displayBackwards ();
323
339
324
340
myList .insertOrdered (23 );
325
341
myList .insertOrdered (67 );
326
342
myList .insertOrdered (3 );
327
343
myList .display (); // <-- 3(head) <--> 10 <--> 13 <--> 23 <--> 67(tail) -->
328
344
myList .insertElementByIndex (5 , 1 );
329
345
myList .display (); // <-- 3(head) <--> 5 <--> 10 <--> 13 <--> 23 <--> 67(tail) -->
330
-
346
+ myList . displayBackwards ();
331
347
myList .reverse (); // <-- 67(head) <--> 23 <--> 13 <--> 10 <--> 5 <--> 3(tail) -->
332
348
myList .display ();
349
+
333
350
myList .clearList ();
334
351
myList .display ();
352
+ myList .displayBackwards ();
335
353
myList .insertHead (20 );
336
354
myList .display ();
355
+ myList .displayBackwards ();
337
356
}
338
357
}
You can’t perform that action at this time.
0 commit comments