Hey Guys I'm revising for a test.The question asks as follows to complete the method.That prints a singly linked list backwards.Using the printBackward method which takes the length of the list as a parameter.
Once you have completed the method create a simple program to print the list forward and then in reverse order using the
printBackward method
I am not sure how to implement this is what I have so far any help would be greatly appreciated.
Once you have completed the method create a simple program to print the list forward and then in reverse order using the
printBackward method
I am not sure how to implement this is what I have so far any help would be greatly appreciated.
import java.util.LinkedList;
import java.util.ListIterator;
@SuppressWarnings("serial")
public class MyLinkedList<E> extends LinkedList<E> {
public void printBackward(Integer n) {
if (n > 0) {
ListIterator<E> itr = listIterator();
int count = 0;
while (itr.hasNext()) {
//Block 1
}
//
} else {
//Block 3
}
}// end method
public static void main(String[] args) {
LinkedList<Integer> myList = new LinkedList<Integer>();
myList.add(34);
myList.add(65);
myList.add(27);
myList.add(89);
myList.add(12);
System.out.println("myList: "+myList);
//printBackward(0);
}
}// end class