Delete all odd nodes of a Circular Linked List | Structure for a node ; Function to insert a node at the beginning of a Circular linked list ; If linked list is not null then set the next of last node ; For the first node ; Delete the node if it is odd ; If node to be deleted is head node ; Traverse list till not found delete node ; copy address of node ; Function to delete all odd nodes from the singly circular linked list ; Traverse list till the end if the node is odd then delete it ; If node is odd ; Point to next node ; Function to print nodes ; Initialize lists as empty ; Created linked list will be 56 -> 61 -> 57 -> 11 -> 12 -> 2
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } ; function push ( head_ref , data ) { var ptr1 = new Node ( ) ; var temp = head_ref ; ptr1 . data = data ; ptr1 . next = head_ref ; if ( head_ref != null ) { while ( temp . next != head_ref ) temp = temp . next ; temp . next = ptr1 ; return head_ref ; } else ptr1 . next = ptr1 ; head_ref = ptr1 ; return head_ref ; } function deleteNode ( head_ref , del ) { var temp = head_ref ; if ( head_ref == del ) head_ref = del . next ; while ( temp . next != del ) { temp = temp . next ; } temp . next = del . next ; return head_ref ; } function deleteoddNodes ( head ) { var ptr = head ; var next ; do { if ( ptr . data % 2 == 1 ) deleteNode ( head , ptr ) ; next = ptr . next ; ptr = next ; } while ( ptr != head ) ; return head ; } function printList ( head ) { var temp = head ; if ( head != null ) { do { document . write ( temp . data + " " ) ; temp = temp . next ; } while ( temp != head ) ; } } var head = null ; head = push ( head , 2 ) ; head = push ( head , 12 ) ; head = push ( head , 11 ) ; head = push ( head , 57 ) ; head = push ( head , 61 ) ; head = push ( head , 56 ) ; document . write ( " " ) ; head = deleteoddNodes ( head ) ; printList ( head ) ;