File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -243,6 +243,18 @@ public void display() { // Prints contents of the list
243
243
}
244
244
System .out .println ();
245
245
}
246
+
247
+ /**
248
+ * Prints the contents of the list in reverse order
249
+ */
250
+ public void displayBackwards () {
251
+ Link current = tail ;
252
+ while (current != null ) {
253
+ current .displayLink ();
254
+ current = current .previous ;
255
+ }
256
+ System .out .println ();
257
+ }
246
258
}
247
259
248
260
/**
@@ -283,25 +295,32 @@ public static void main(String args[]) {
283
295
myList .insertHead (7 );
284
296
myList .insertHead (10 );
285
297
myList .display (); // <-- 10(head) <--> 7 <--> 13(tail) -->
298
+ myList .displayBackwards ();
286
299
287
300
myList .insertTail (11 );
288
301
myList .display (); // <-- 10(head) <--> 7 <--> 13 <--> 11(tail) -->
302
+ myList .displayBackwards ();
289
303
290
304
myList .deleteTail ();
291
305
myList .display (); // <-- 10(head) <--> 7 <--> 13(tail) -->
306
+ myList .displayBackwards ();
292
307
293
308
myList .delete (7 );
294
309
myList .display (); // <-- 10(head) <--> 13(tail) -->
310
+ myList .displayBackwards ();
295
311
296
312
myList .insertOrdered (23 );
297
313
myList .insertOrdered (67 );
298
314
myList .insertOrdered (3 );
299
315
myList .display (); // <-- 3(head) <--> 10 <--> 13 <--> 23 <--> 67(tail) -->
300
316
myList .insertElementByIndex (5 , 1 );
301
317
myList .display (); // <-- 3(head) <--> 5 <--> 10 <--> 13 <--> 23 <--> 67(tail) -->
318
+ myList .displayBackwards ();
302
319
myList .clearList ();
303
320
myList .display ();
321
+ myList .displayBackwards ();
304
322
myList .insertHead (20 );
305
323
myList .display ();
324
+ myList .displayBackwards ();
306
325
}
307
326
}
You can’t perform that action at this time.
0 commit comments