codeparrot/xlcost-text-to-code huggingface dataset:
Remove all the Even Digit Sum Nodes from a Circular Singly Linked List | Structure for a node ; Function to insert a node at the beginning of a Circular linked list ; Create a new node and make head as next of it . ; If linked list is not null then set the next of last node ; Find the node before head and update next of it . ; Povar for the first node ; Function to delete the node from a Circular Linked list ; If node to be deleted is head node ; Traverse list till not found delete node ; Copy the address of the node ; Finally , free the memory occupied by del ; Function to find the digit sum for a number ; Function to delete all the Even Digit Sum Nodes from the singly circular linked list ; Traverse the list till the end ; If the node ' s ▁ data ▁ is ▁ Fibonacci , ▁ ▁ delete ▁ node ▁ ' ptr ' ; Povar to the next node ; Function to prvar nodes in a given Circular linked list ; Initialize lists as empty ; Created linked list will be 9.11 .34 .6 .13 .21
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 ; } 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 ; del = null ; return ; } function digitSum ( num ) { var sum = 0 ; while ( num > 0 ) { sum += ( num % 10 ) ; num = parseInt ( num / 10 ) ; } return sum ; } function deleteEvenDigitSumNodes ( head ) { var ptr = head ; var next ; do { if ( ! ( digitSum ( ptr . data ) % 2 == 1 ) ) deleteNode ( head , ptr ) ; next = ptr . next ; ptr = next ; } while ( ptr != 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 , 21 ) ; head = push ( head , 13 ) ; head = push ( head , 6 ) ; head = push ( head , 34 ) ; head = push ( head , 11 ) ; head = push ( head , 9 ) ; deleteEvenDigitSumNodes ( head ) ; printList ( head ) ;
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 ) ;
Insertion in a sorted circular linked list when a random pointer is given | Node structure ; Function to create a node ; Function to find and return the head ; If the list is empty ; Finding the last node of the linked list the last node must have the highest value if no such element is present then all the nodes of the linked list must be same ; Return the head ; Function to insert a new_node in the list in sorted fashion . Note that this function expects a pointer to head node as this can modify the head of the input linked list ; If the list is empty ; If the node to be inserted is the smallest then it has to be the new head ; Find the last node of the list as it will be pointing to the head ; Locate the node before the povar of insertion ; Return the new head ; Function to prvar the nodes of the linked list ; Driver code ; Start with an empty linked list ; Create linked list from the given array ; Move to a random node if it exists ; Prvar the contents of the created list
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } function create ( ) { var new_node = new Node ( ) ; new_node . next = null ; return new_node ; } function find_head ( random ) { if ( random == null ) return null ; var head , vari = random ; while ( ! ( vari . data > vari . next . data vari . next == random ) ) { vari = vari . next ; } return vari . next ; } function sortedInsert ( head_ref , new_node ) { var current = head_ref ; if ( current == null ) { new_node . next = new_node ; head_ref = new_node ; } else if ( current . data >= new_node . data ) { while ( current . next != head_ref ) current = current . next ; current . next = new_node ; new_node . next = head_ref ; head_ref = new_node ; } else { while ( current . next != head_ref && current . next . data < new_node . data ) { current = current . next ; } new_node . next = current . next ; current . next = new_node ; } return head_ref ; } function printList ( start ) { var temp ; if ( start != null ) { temp = start ; do { document . write ( temp . data + " " ) ; temp = temp . next ; } while ( temp != start ) ; } } var arr = [ 12 , 56 , 2 , 11 , 1 , 90 ] ; var list_size , i ; var start = null ; var temp ; for ( i = 0 ; i < 6 ; i ++ ) { if ( start != null ) for ( j = 0 ; j < ( Math . random ( ) * 10 ) ; j ++ ) start = start . next ; temp = create ( ) ; temp . data = arr [ i ] ; start = sortedInsert ( find_head ( start ) , temp ) ; } printList ( find_head ( start ) ) ;
Splitting starting N nodes into new Circular Linked List while preserving the old nodes | Javascript implementation of the approach ; Function to add a node to the empty list ; If not empty ; Creating a node dynamically ; Assigning the data ; Creating the link ; Function to add a node to the beginning of the list ; If list is empty ; Create node ; Assign data ; Function to traverse and print the list ; If list is empty ; Pointing to the first Node of the list ; Traversing the list ; Function to find the length of the CircularLinkedList ; Stores the length ; List is empty ; Iterator Node to traverse the List ; Return the length of the list ; Function to split the first k nodes into a new CircularLinkedList and the remaining nodes stay in the original CircularLinkedList ; Empty Node for reference ; Check if the list is empty If yes , then return null ; NewLast will contain the last node of the new split list itr to iterate the node till the required node ; Update NewLast to the required node and link the last to the start of rest of the list ; Return the last node of the required list ; Driver code ; Append the new last node into the new list ; Print the new lists
class Node { constructor ( ) { let data ; let next ; } } function addToEmpty ( last , data ) { if ( last != null ) return last ; let temp = new Node ( ) ; temp . data = data ; last = temp ; last . next = last ; return last ; } function addBegin ( last , data ) { if ( last == null ) return addToEmpty ( data ) ; let temp = new Node ( ) ; temp . data = data ; temp . next = last . next ; last . next = temp ; return last ; } function traverse ( last ) { let p ; if ( last == null ) { document . write ( " " ) ; return ; } p = last . next ; do { document . write ( p . data + " " ) ; p = p . next ; } while ( p != last . next ) ; document . write ( " " ) ; } function length ( last ) { let x = 0 ; if ( last == null ) return x ; let itr = last . next ; while ( itr . next != last . next ) { x ++ ; itr = itr . next ; } return ( x + 1 ) ; } function split ( last , k ) { let pass = new Node ( ) ; if ( last == null ) return last ; let newLast , itr = last ; for ( let i = 0 ; i < k ; i ++ ) { itr = itr . next ; } newLast = itr ; pass . next = itr . next ; newLast . next = last . next ; last . next = pass . next ; return newLast ; } let clist = null ; clist = addToEmpty ( clist , 12 ) ; clist = addBegin ( clist , 10 ) ; clist = addBegin ( clist , 8 ) ; clist = addBegin ( clist , 6 ) ; clist = addBegin ( clist , 4 ) ; clist = addBegin ( clist , 2 ) ; document . write ( " " ) ; traverse ( clist ) ; let k = 4 ; let clist2 = split ( clist , k ) document . write ( " " ) ; traverse ( clist2 ) ; traverse ( clist ) ;
Convert a given Binary Tree to Circular Doubly Linked List | Set 2 | A binary tree node has data , and left and right pointers ; Function to perform In - Order traversal of the tree and store the nodes in a vector ; first recur on left child ; append the data of node in vector ; now recur on right child ; Function to convert Binary Tree to Circular Doubly Linked list using the vector which stores In - Order traversal of the Binary Tree ; Base cases ; Vector to be used for storing the nodes of tree in In - order form ; Calling the In - Order traversal function ; Create the head of the linked list pointing to the root of the tree ; Create a current pointer to be used in traversal ; Traversing the nodes of the tree starting from the second elements ; Create a temporary pointer pointing to current ; Current 's right points to the current  node in traversal ; Current points to its right ; Current 's left points to temp ; Current 's right points to head of the list ; Head 's left points to current ; Return head of the list ; Display Circular Link List ; Driver Code
class Node { constructor ( val ) { this . data = val ; this . left = null ; this . right = null ; } } function inorder ( root , v ) { if ( root == null ) return ; inorder ( root . left , v ) ; v . push ( root . data ) ; inorder ( root . right , v ) ; } function bTreeToCList ( root ) { if ( root == null ) return null ; var v = [ ] ; inorder ( root , v ) ; var head_ref = new Node ( v [ 0 ] ) ; var curr = head_ref ; for ( i = 1 ; i < v . length ; i ++ ) { var temp = curr ; curr . right = new Node ( v [ i ] ) ; curr = curr . right ; curr . left = temp ; } curr . right = head_ref ; head_ref . left = curr ; return head_ref ; } function displayCList ( head ) { document . write ( " " ) ; var itr = head ; do { document . write ( itr . data + " " ) ; itr = itr . right ; } while ( head != itr ) ; document . write ( ) ; } var root = new Node ( 10 ) ; root . left = new Node ( 12 ) ; root . right = new Node ( 15 ) ; root . left . left = new Node ( 25 ) ; root . left . right = new Node ( 30 ) ; root . right . left = new Node ( 36 ) ; var head = bTreeToCList ( root ) ; displayCList ( head ) ;
Delete all odd or even positioned nodes from Circular Linked List | Function to delete that all node whose index position is odd ; Check list have any node if not then return ; If list have single node means odd position then delete it ; Traverse first to last if list have more than one node ; Delete first position node which is odd position ; Function to delete first node ; Check position is odd or not if yes then delete node Note : Considered 1 based indexing
function DeleteAllOddNode ( head ) { let len = Length ( head ) ; let count = 0 ; var previous = head , next = head ; if ( head == null ) { document . write ( " " + " " + " " ) ; return null ; } if ( len == 1 ) { head = DeleteFirst ( head ) ; return head ; } while ( len > 0 ) { if ( count == 0 ) { head = DeleteFirst ( head ) ; } if ( count % 2 == 0 && count != 0 ) { head = deleteNode ( head , previous ) ; } previous = previous . next ; next = previous . next ; len -- ; count ++ ; } return head ; }
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 ; }
Deletion at different positions in a Circular Linked List |  ; Check if list doesn 't have any node  if not then return ; Check if list have single node if yes then delete it and return ; Traverse second node to first ; Now previous is last node and first node ( firstNode ) link address put in last node ( previous ) link ; Make second node as head node
function DeleteFirst ( head ) { previous = head , firstNode = head ; if ( head == null ) { document . write ( " " ) ; return ; } if ( previous . next == previous ) { head = null ; return ; } while ( previous . next != head ) { previous = previous . next ; } previous . next = firstNode . next ; head = previous . next ; return ; }
Deletion at different positions in a Circular Linked List |  ; Check if list doesn 't have any node  if not then return ; Check if list have single node if yes then delete it and return ; Move first node to last previous
function DeleteLast ( head ) { let current = head , temp = head , previous = null ; if ( head == null ) { document . write ( " " ) ; return null ; } if ( current . next == current ) { head = null ; return null ; } while ( current . next != head ) { previous = current ; current = current . next ; } previous . next = current . next ; head = previous . next ; return head ; }
Find minimum and maximum elements in singly Circular Linked List | structure for a node ; Function to prvar minimum and maximum nodes of the circular linked list ; check list is empty ; pointer for traversing ; initialize head to current pointer ; initialize max var value to min initialize min var value to max ; While last node is not reached ; If current node data is lesser for min then replace it ; If current node data is greater for max then replace it ; Function to insert a node at the end of a Circular linked list ; Create a new node ; check node is created or not ; insert data into newly created node ; check list is empty if not have any node then make first node it ; if list have already some node ; move firt node to last node ; put first or head node address in new node link ; put new node address into last node link ( next ) ; Function to prvar the Circular linked list ; if list is empty simply show message ; traverse first to last node ; Driver Code
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function printMinMax ( head ) { if ( head == null ) { return ; } var current ; current = head ; var min = Number . MAX_VALUE , max = Number . MIN_VALUE ; while ( current . next != head ) { if ( current . data < min ) { min = current . data ; } if ( current . data > max ) { max = current . data ; } current = current . next ; } document . write ( " " + min + " " + max ) ; } function insertNode ( head , data ) { var current = head ; var newNode = new Node ( ) ; if ( newNode == null ) { document . write ( " " ) ; return null ; } newNode . data = data ; if ( head == null ) { newNode . next = newNode ; head = newNode ; return head ; } else { while ( current . next != head ) { current = current . next ; } newNode . next = head ; current . next = newNode ; } return head ; } function displayList ( head ) { var current = head ; if ( head == null ) { document . write ( " " ) ; return ; } else { do { document . write ( current . data + " " ) ; current = current . next ; } while ( current != head ) ; } } var Head = null ; Head = insertNode ( Head , 99 ) ; Head = insertNode ( Head , 11 ) ; Head = insertNode ( Head , 22 ) ; Head = insertNode ( Head , 33 ) ; Head = insertNode ( Head , 44 ) ; Head = insertNode ( Head , 55 ) ; Head = insertNode ( Head , 66 ) ; document . write ( " " ) ; displayList ( Head ) ; printMinMax ( Head ) ;
Delete all the even 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 even ; If node to be deleted is head node ; traverse list till not found delete node ; copy address of node ; Function to delete all even nodes from the singly circular linked list ; traverse list till the end if the node is even then delete it ; if node is even ; povar to next node ; Function to prvar nodes ; Initialize lists as empty ; Created linked list will be 57.11 .2 .56 .12 .61
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 deleteEvenNodes ( head ) { var ptr = head ; var next ; do { if ( ptr . data % 2 == 0 ) 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 , 61 ) ; head = push ( head , 12 ) ; head = push ( head , 56 ) ; head = push ( head , 2 ) ; head = push ( head , 11 ) ; head = push ( head , 57 ) ; document . write ( " " ) ; head = deleteEvenNodes ( head ) ; printList ( head ) ;
Sum of the 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 ; Function to find sum of the given Circular linked list ; Initialize lists as empty ; Created linked list will be 11.2 .56 .12
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 ; } else ptr1 . next = ptr1 ; head_ref = ptr1 ; return head_ref ; } function sumOfList ( head ) { var temp = head ; var sum = 0 ; if ( head != null ) { do { temp = temp . next ; sum += temp . data ; } while ( temp != head ) ; } return sum ; } var head = null ; head = push ( head , 12 ) ; head = push ( head , 56 ) ; head = push ( head , 2 ) ; head = push ( head , 11 ) ; document . write ( " " + " " + sumOfList ( head ) ) ;
Delete every Kth node from circular linked list | structure for a Node ; * Utility function to prvar the circular linked list ; Function to delete every kth Node ; If list is empty , simply return . ; take two pointers - current and previous ; Check if Node is the only Node \ If yes , we reached the goal , therefore return . ; Prvar intermediate list . ; If more than one Node present in the list , Make previous pointer povar to current Iterate current pointer k times , i . e . current Node is to be deleted . ; If Node to be deleted is head ; If Node to be deleted is last Node . ; * Function to insert a Node at the end of a Circular linked list ; Create a new Node ; if the list is empty , make the new Node head Also , it will povar to itself . ; traverse the list to reach the last Node and insert the Node ; insert Nodes in the circular linked list ; Delete every kth Node from the circular linked list .
class Node { constructor ( val ) { this . data = val ; this . next = null ; } } function printList ( head ) { if ( head == null ) return ; var temp = head ; do { document . write ( temp . data + " " ) ; temp = temp . next ; } while ( temp != head ) ; document . write ( head . data + " " ) ; } function deleteK ( head_ref , k ) { var head = head_ref ; if ( head == null ) return null ; var curr = head , prev = null ; while ( true ) { if ( curr . next == head && curr == head ) break ; printList ( head ) ; for ( i = 0 ; i < k ; i ++ ) { prev = curr ; curr = curr . next ; } if ( curr == head ) { prev = head ; while ( prev . next != head ) prev = prev . next ; head = curr . next ; prev . next = head ; head_ref = head ; } else if ( curr . next == head ) { prev . next = head ; } else { prev . next = curr . next ; } } return head ; } function insertNode ( head_ref , x ) { var head = head_ref ; var temp = new Node ( x ) ; if ( head == null ) { temp . next = temp ; head_ref = temp ; return head_ref ; } else { var temp1 = head ; while ( temp1 . next != head ) temp1 = temp1 . next ; temp1 . next = temp ; temp . next = head ; } return head ; } var head = null ; head = insertNode ( head , 1 ) ; head = insertNode ( head , 2 ) ; head = insertNode ( head , 3 ) ; head = insertNode ( head , 4 ) ; head = insertNode ( head , 5 ) ; head = insertNode ( head , 6 ) ; head = insertNode ( head , 7 ) ; head = insertNode ( head , 8 ) ; head = insertNode ( head , 9 ) ; var k = 4 ; head = deleteK ( head , k ) ;