public static < E extends Comparable < E > > boolean isSorted ( E [ ] array ) { for ( int i = 0 ; i < array . length - 1 ; i ++ ) { if ( array [ i ] . compareTo ( array [ i + 1 ] ) > 0 ) { return false ; } } return true ; }
Check if the array is sorted . It loops through the entire array once checking that the elements are sorted .