Driver code to test above
for ( let i = 8 ; i >= 1 ; i -- ) push ( i ) ; document . write ( " " ) ; printList ( ) ; document . write ( " " ) ; for ( let i = 1 ; i < 9 ; i ++ ) { swapKth ( i ) ; document . write ( " " + i + " " ) ; printList ( ) ; document . write ( " " ) ; }