Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. int is_sorted(const int *a, int n);
  2. // REQUIRES: n >= 1. Elements a[0] ... a[n-1] exist.
  3. // PROMISES
  4. //   Return value is  1 if n == 1, or if n > 1 and all of
  5. //   a[0] <= a[1] ... a[n-2] <= a[n-1] are true.  
  6. //   Otherwise, return value is 0.
  7.  
  8. int all_different(const int *a, int n);
  9. // REQUIRES: n > 1. Elements a[0] ... a[n-1] exist.
  10. // PROMISES: Return value is 1 if no two elements among
  11. // a[0] ... a[n-1] are equal to each other.
  12. //   Otherwise, return value is 0.
  13.  
  14. int is_alternating(const int *a, int n);
  15. // Decides whether array elements form an alternating sequence.  In an
  16. // alternating sequence, each number has the opposite sign of the
  17. // previous number in the sequence.  Zero is neither positive nor negative,
  18. // so any sequence that includes 0 is not an alternating sqeuence
  19. //
  20. // Examples: {-1, 1, -1, 1} and {1, -1, 2, -3, 5} are alternating sequences,
  21. // but {-2, 3, 4, -5} and {10, -20, 0, -30} are not.
  22. //
  23. // REQUIRES: n >= 1. Elements a[0] ... a[n-1] exist.
  24. // PROMISES
  25. //    The return value is 1 if n == 1.
  26. //    If n > 1, the return value is 1 if a[0] ... a[n-1] form
  27. //    an alternating sequence.
  28. // PROMISES
  29. //    Otherwise, the return value is 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement