Driver code to test above
public static void main ( String [ ] args ) { LinkedList llist = new LinkedList ( ) ; for ( int i = 8 ; i >= 1 ; i -- ) llist . push ( i ) ; System . out . print ( " Original ▁ linked ▁ list : ▁ " ) ; llist . printList ( ) ; System . out . println ( " " ) ; for ( int i = 1 ; i < 9 ; i ++ ) { llist . swapKth ( i ) ; System . out . println ( " Modified ▁ List ▁ for ▁ k ▁ = ▁ " + i ) ; llist . printList ( ) ; System . out . println ( " " ) ; } } }