Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "elements.h"
- #include <stddef.h>
- #include <stdbool.h>
- static int compare(const element *a, const element *b)
- {
- if (a->e2 == b->e2)
- return 0;
- else if (a->e1 != b->e1)
- return b->e1 - a->e1;
- return b->e2 - a->e2;
- }
- size_t count_unique(const element *s)
- {
- size_t c = 0;
- bool found;
- for (size_t i = 0; s[i].s != NULL; ++i) {
- found = false;
- for (size_t j = 0; j < i; ++j) {
- if (compare(&s[i], &s[j]) == 0) {
- found = true;
- break;
- }
- }
- if (!found)
- c++;
- }
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement