import java.util.LinkedList;
import java.util.Iterator;
public class DoubleList2<T> extends LinkedList<T> {
public void print(){
for (T current : this) {
System.out.println(current);
}
}
public void printReverse(){
Iterator<T> iter=this.descendingIterator();
while (iter.hasNext())
System.out.println(iter.next());
}
public static void main(String[] args){
DoubleList2<String> test=new DoubleList2<>();
test.addLast("hello");
test.addFirst("goodbye");
test.addLast("are you still here");
System.out.println("\nForward:");
test.print();
System.out.println("\nReverse:");
test.printReverse();
System.out.println("\nAfter Removing First:");
test.removeFirst();
test.print();
System.out.println("\nAfter Removing Last:");
test.removeLast();
test.print();
System.out.println("\nAfter Removing Last, again");
test.removeLast();
test.print();
test.addLast("a");
test.addLast("b");
test.addLast("c");
test.addLast("d");
test.addLast("e");
test.addLast("f");
System.out.println("\nRebuilt list");
test.print();
test.remove("a");
System.out.println("\n Remove first, by key");
test.print();
test.remove("c");
System.out.println("\n Remove middle, by key");
test.print();
test.remove("f");
System.out.println("\n Remove last, by key");
test.print();
}
}
//