Bitonic point in the given linked list | Node for linked list ; Function to insert a node at the head of the linked list ; Function to return the bitonic of the given linked list ; If list is empty ; If list contains only a single node ; Invalid bitonic sequence ; If current node is the bitonic point ; Get to the next node in the list ; Nodes must be in descending starting from here ; Out of order node ; Get to the next node in the list ; Driver code
class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = None NEW_LINE DEDENT DEDENT def push ( head_ref , data ) : NEW_LINE INDENT new_node = Node ( data ) NEW_LINE new_node . next = head_ref NEW_LINE head_ref = new_node NEW_LINE return head_ref NEW_LINE DEDENT def bitonic_point ( node ) : NEW_LINE INDENT if ( node == None ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT if ( node . next == None ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT if ( node . data > node . next . data ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT while ( node . next != None ) : NEW_LINE INDENT if ( node . data > node . next . data ) : NEW_LINE INDENT break ; NEW_LINE DEDENT node = node . next ; NEW_LINE DEDENT bitonicPoint = node . data ; NEW_LINE while ( node . next != None ) : NEW_LINE INDENT if ( node . data < node . next . data ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT node = node . next ; NEW_LINE DEDENT return bitonicPoint ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None ; NEW_LINE head = push ( head , 100 ) ; NEW_LINE head = push ( head , 201 ) ; NEW_LINE head = push ( head , 399 ) ; NEW_LINE head = push ( head , 490 ) ; NEW_LINE head = push ( head , 377 ) ; NEW_LINE head = push ( head , 291 ) ; NEW_LINE head = push ( head , 100 ) ; NEW_LINE print ( bitonic_point ( head ) ) NEW_LINE DEDENT