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";
No comments:
Post a Comment