public static void main(String[] args) { MyLinkedList<Integer> l = new MyLinkedList<Integer>(); l.add(4); l.add(8); l.add(9); l.add(7); l.add(12); System.out.println(l); // System.out.println(l.indexOf(9)); System.out.println("element at 3 is: " + l.get(3)); // System.out.println(l.set(2,99)); l.set(2, 99); // System.out.println(l); l.add(3, 23); System.out.println(l); System.out.println("Removed: " + l.remove(4)); l.add(20); System.out.println(l); int j = 0; for (Integer i : l) { System.out.println(i); } MyLinkedList<String> z = new MyLinkedList<String>(); z.add("a"); z.add("b"); z.add("c"); // System.out.println(z); }
public static void main(String[] args) { MyLinkedList L = new MyLinkedList(); System.out.println("Adding four nodes..."); L.add("Sully"); L.add("Mike"); L.add("Randall"); L.add("Boo"); System.out.println(L); System.out.println(); System.out.println("Adding new node at 1..."); L.add(1, "New Node"); System.out.println(L); System.out.println("Adding another new node at 3..."); L.add(3, "Another New Node"); System.out.println(L); System.out.println(); System.out.println("Node at index 3: " + L.get(3)); System.out.println(); System.out.println("Replacing index 3 with a replacement node"); L.set(3, "A Replacement Node"); System.out.println(L); System.out.println(); System.out.println("Removing node at 3..."); L.remove(3); System.out.println(L); System.out.println("Removing node at 0..."); L.remove(0); System.out.println(L); System.out.println(); System.out.println("Finding " + L.get(3) + " : " + L.find(L.get(3))); System.out.println(); System.out.println("Total length of linked list: " + L.size()); }