Bitonic point in the given linked list | C ++ implementation of the approach ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; class Node { public : int data ; Node * next ; } ; Node * push ( Node * * head_ref , int data ) { Node * new_node = new Node ; new_node -> data = data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } int bitonic_point ( Node * node ) { if ( node == NULL ) return -1 ; if ( node -> next == NULL ) return -1 ; if ( node -> data > node -> next -> data ) return -1 ; while ( node -> next != NULL ) { if ( node -> data > node -> next -> data ) break ; node = node -> next ; } int bitonicPoint = node -> data ; while ( node -> next != NULL ) { if ( node -> data < node -> next -> data ) return -1 ; node = node -> next ; } return bitonicPoint ; } int main ( ) { Node * head = NULL ; push ( & head , 100 ) ; push ( & head , 201 ) ; push ( & head , 399 ) ; push ( & head , 490 ) ; push ( & head , 377 ) ; push ( & head , 291 ) ; push ( & head , 100 ) ; cout << bitonic_point ( head ) ; return 0 ; }