how can we know this array is sorted in java

this is easy example

        int o = a[0] < a[1] ? 0 :1;
 for (int i = 1; i < a.length-1; i++) 
   if( 0!= (a[i] < a[i+1]?0:1) )   return "not sorted";
 return o ==0?"ascending" : "descending";

Comments

Popular posts from this blog

Project euler 169 found clue

Floyd-Warshall's algorithm