Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int is_sorted(const int *a, int n);
- // REQUIRES: n >= 1. Elements a[0] ... a[n-1] exist.
- // PROMISES
- // Return value is 1 if n == 1, or if n > 1 and all of
- // a[0] <= a[1] ... a[n-2] <= a[n-1] are true.
- // Otherwise, return value is 0.
- int all_different(const int *a, int n);
- // REQUIRES: n > 1. Elements a[0] ... a[n-1] exist.
- // PROMISES: Return value is 1 if no two elements among
- // a[0] ... a[n-1] are equal to each other.
- // Otherwise, return value is 0.
- int is_alternating(const int *a, int n);
- // Decides whether array elements form an alternating sequence. In an
- // alternating sequence, each number has the opposite sign of the
- // previous number in the sequence. Zero is neither positive nor negative,
- // so any sequence that includes 0 is not an alternating sqeuence
- //
- // Examples: {-1, 1, -1, 1} and {1, -1, 2, -3, 5} are alternating sequences,
- // but {-2, 3, 4, -5} and {10, -20, 0, -30} are not.
- //
- // REQUIRES: n >= 1. Elements a[0] ... a[n-1] exist.
- // PROMISES
- // The return value is 1 if n == 1.
- // If n > 1, the return value is 1 if a[0] ... a[n-1] form
- // an alternating sequence.
- // PROMISES
- // Otherwise, the return value is 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement