Check whether the length of given linked list is Even or Odd | Defining structure ; Function to check the length of linklist ; Push function ; Allocating node ; Info into node ; Next of new node to head ; head points to new node ; Driver code ; Adding elements to Linked List ; Checking for length of linklist
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function LinkedListLength ( head ) { while ( head != null && head . next != null ) { head = head . next . next ; } if ( head == null ) return 0 ; return 1 ; } function push ( head , info ) { node = new Node ( ) ; node . data = info ; node . next = ( head ) ; ( head ) = node ; } head = null ; push ( head , 4 ) ; push ( head , 5 ) ; push ( head , 7 ) ; push ( head , 2 ) ; push ( head , 9 ) ; push ( head , 6 ) ; push ( head , 1 ) ; push ( head , 2 ) ; push ( head , 0 ) ; push ( head , 5 ) ; push ( head , 5 ) ; var check = LinkedListLength ( head ) ; if ( check == 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; }