text: Program to check if an array is sorted or not ( Iterative and Recursive ) | Recursive approach to check if an Array is sorted or not ; Function that returns true if array is sorted in non - decreasing order . ; Array has one or no element ; Unsorted pair found ; No unsorted pair found ; Driver code
code: using System ; class GFG { static bool arraySortedOrNot ( 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 = { 20 , 23 , 23 , 45 , 78 , 88 } ; int n = arr . Length ; if ( arraySortedOrNot ( arr , n ) ) Console . Write ( " Yes STRNEWLINE " ) ; else Console . Write ( " No STRNEWLINE " ) ; } }