import rpi.goldsd.container.*; public class LinkedListTest { public static void main( String[] args ) { LinkedList L = new LinkedList(); if ( L.isEmpty() ) System.out.println( "List is initially empty." ); ListNode N0 = new ListNode( new Int(7) ); L.addToHead( N0 ); L.addToHead( new ListNode( new Int(7) ) ); L.addToTail( new ListNode( new Int(12) ) ); L.addToTail( new ListNode( new Int(20) ) ); ListNode N1 = new ListNode( new Int(18) ); L.addToHead( N1 ); ListNode N2 = new ListNode( new Int(24) ); L.addToTail( N2 ); System.out.println( L ); L.addAfter( N1, new ListNode( new Int(15) ) ); L.addAfter( N1, new ListNode( new Int(16) ) ); L.addAfter( N2, new ListNode( new Int(30) ) ); ListNode N3 = new ListNode( new Int(8) ); L.addAfter( N0, N3 ); L.addAfter( N3, new ListNode( new Int(9) ) ); L.addAfter( N3, new ListNode( new Int(10) ) ); System.out.println( L ); if ( L.contains( new Int(10) ) ) System.out.println( "10 is currently in the list [contains()]." ); else System.out.println( "10 is not currently in the list [contains()]." ); if ( L.contains( new ListNode( new Int(47) ) ) ) System.out.println( "47 is currently in the list [contains()]." ); else System.out.println( "47 is not currently in the list [contains()]." ); if ( L.containsReferenceTo( N1 ) ) System.out.println( N1 + " is currently in the list [containsReferenceTo()]." ); else System.out.println( N1 + " is not currently in the list [containsReferenceTo()]." ); ListNode N4 = new ListNode( new Int(8) ); if ( L.containsReferenceTo( N4 ) ) System.out.println( N4 + " is currently in the list [containsReferenceTo()]." ); else System.out.println( N4 + " is not currently in the list [containsReferenceTo()]." ); if ( L.isEmpty() ) System.out.println( "FATAL ERROR -- LIST IS EMPTY!" ); System.out.println( "The list contains " + L.getSize() + " elements." ); L.remove( new Int(16) ); L.remove( N3 ); L.remove( new Int(18) ); L.remove( new Int(30) ); System.out.println( L ); System.out.println( "Now the list contains " + L.getSize() + " elements." ); while ( L.getSize() > 4 ) { ListNode n = L.removeFromTail(); System.out.println( "Removed " + n + " from tail of list." ); } System.out.println( L ); while ( L.getSize() > 0 ) { ListNode n = L.removeFromHead(); System.out.println( "Removed " + n + " from head of list." ); } System.out.println( L ); L.addToHead( N0 ); L.addToTail( N1 ); L.addToTail( N2 ); L.addToTail( N3 ); L.addToTail( N4 ); System.out.println( L ); } }