Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include "elements.h"
  2.  
  3. #include <stddef.h>
  4. #include <stdbool.h>
  5.  
  6. static int compare(const element *a, const element *b)
  7. {
  8. if (a->e2 == b->e2)
  9. return 0;
  10. else if (a->e1 != b->e1)
  11. return b->e1 - a->e1;
  12. return b->e2 - a->e2;
  13. }
  14.  
  15. size_t count_unique(const element *s)
  16. {
  17. size_t c = 0;
  18. bool found;
  19. for (size_t i = 0; s[i].s != NULL; ++i) {
  20. found = false;
  21. for (size_t j = 0; j < i; ++j) {
  22. if (compare(&s[i], &s[j]) == 0) {
  23. found = true;
  24. break;
  25. }
  26. }
  27. if (!found)
  28. c++;
  29. }
  30. return c;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement