# C++ Notes: Algorithms: isSorted

Returns true if the array is sorted (ascending), otherwise returns false.

    bool isSorted(int a[], int first, int last) {
       // parameters:
       //    a       in  array of values.
       //    first   in  first index in a to test
       //    last    in  last index in a to test
       // returns: true if array is sorted, else false.

       // Look at all adjacent pairs.  If any pair is out of order, it's unsorted
       for (int i=first; i<last; i++) {
           if (a[i] > a[i+1]) {
               return false;   // not sorted, return immediately
           }
       }
       return true;  // it is sorted if loop finished
    }