Monday, September 27, 2010

Reality Check

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