Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- const char pr[] = {'2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A', 'c', 's', 'h', 'd' };
- inline int prior(char c) {
- int ans = 0;
- while (pr[ans]!=c) ans++;
- return ans;
- }
- int comp(const void *p1, const void *p2) {
- const struct Card *a = (Card *)p1;
- const struct Card *b = (Card *)p2;
- if (a->suit == b->suit) {
- if (prior(a->rank)<prior(b->rank)) return -1;
- return 1;
- }
- if (prior(a->suit)<prior(b->suit)) return -1;
- return 1;
- }
- void sort_card(int n, Card card[]) {
- qsort(card, n, sizeof(Card), comp);
- }
Advertisement
Add Comment
Please, Sign In to add comment