public boolean isSorted(int[] list)
{
if(list.length <= 1)
return true;
for(int c = 1; c < list.length; c++)
{
if(list[c] < list[c - 1])
return false;
}
return true;
}
Yes, it works. And in O(n) time.
No comments:
Post a Comment