Check if an array represents Inorder of Binary Search tree or not | Java program to check if a given array is sorted or not . ; Function that returns true if array is Inorder traversal of any Binary Search Tree or not . ; Array has one or no element ; Unsorted pair found ; No unsorted pair found ; Drivers code
class GFG { static boolean isInorder ( int [ ] arr , int n ) { if ( n == 0 n == 1 ) { return true ; } for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i - 1 ] > arr [ i ] ) { return false ; } } return true ; } public static void main ( String [ ] args ) { int arr [ ] = { 19 , 23 , 25 , 30 , 45 } ; int n = arr . length ; if ( isInorder ( arr , n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " Non " ) ; } } }