C# sorting arrays in ascending and descending order

前端 未结 7 1071
感动是毒
感动是毒 2020-12-19 02:27

I\'m having trouble writing a method that returns true if the elements of an array (numbers) are in sorted order, ascending or descending, and false, if they are not in any

7条回答
  •  长情又很酷
    2020-12-19 03:17

    public static boolean checkSortedness(final int[] data) 
    {
        for (int i = 1; i < data.length; i++) 
        {
            if (data[i-1] > data[i]) {
                return false;
            }
        }
        return true;
    }
    

提交回复
热议问题