You are viewing a single comment's thread. Return to all comments →
Using ArrayList :
static void reversePrint(SinglyLinkedListNode head) { SinglyLinkedListNode temp; ArrayList cars = new ArrayList(); temp = head; while(temp!=null) { cars.add(temp.data); temp = temp.next; } for(int i = cars.size()-1; i>=0; i--) { System.out.println(cars.get(i)); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Print in Reverse
You are viewing a single comment's thread. Return to all comments →
Using ArrayList :
static void reversePrint(SinglyLinkedListNode head) { SinglyLinkedListNode temp; ArrayList cars = new ArrayList(); temp = head; while(temp!=null) { cars.add(temp.data); temp = temp.next; } for(int i = cars.size()-1; i>=0; i--) { System.out.println(cars.get(i)); } }