Delete all odd or even positioned nodes from Circular Linked List | Function to delete all even position nodes ; Take size of list ; Check list is empty if empty simply return ; if list have single node then return ; make first node is previous ; make second node is current ; check node number is even if node is even then delete that node
function DeleteAllEvenNode ( head ) { var len = Length ( head ) ; var count = 1 ; var previous = head , next = head ; if ( head == null ) { document . write ( " " ) ; return null ; } if ( len < 2 ) { return null ; } previous = head ; next = previous . next ; while ( len > 0 ) { if ( count % 2 == 0 ) { previous . next = next . next ; previous = next . next ; next = previous . next ; } len -- ; count ++ ; } return head ; }