We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Translated into Python. In Pytohn head = Node(0, None, None)
defSortedInsert(head,data):new_node=Node()new_node.data=data# in the unlikely event new node data < 0? ifnew_node.data<head.data:new_node.next=headhead.prev=new_nodereturnnew_nodeelse:this_node=headthat_node=head.nextwhile((that_node!=None)and(new_node.data>that_node.data)):this_node=that_nodethat_node=that_node.nextifthat_node==None:this_node.next=new_nodenew_node.prev=this_nodeelse:this_node.next=new_nodethat_node.prev=new_nodenew_node.prev=this_nodenew_node.next=that_nodethis_node=headwhilethis_node!=None:this_node=this_node.nextreturnhead
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →
Translated into Python. In Pytohn head = Node(0, None, None)