Function to print the list elements
function printList ( ) { var trav = head ; if ( head == null ) document . write ( " " ) ; while ( trav != null ) { document . write ( trav . val + " " ) ; trav = trav . next ; } }