Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.0KB

  1. #include <stdio.h>
  2. #include "utlist.h"
  3. typedef struct el {
  4. int id, score;
  5. struct el *next, *prev;
  6. } el;
  7. static int order_desc(el *a, el *b)
  8. {
  9. return (a->score > b->score) ? -1 : (a->score < b->score);
  10. }
  11. int main()
  12. {
  13. int i;
  14. el *head = NULL;
  15. el els[15], *e;
  16. for (i=0; i<15; i++) {
  17. els[i].id = (int)'a'+i;
  18. els[i].score = i%7;
  19. LL_INSERT_INORDER(head, &els[i], order_desc);
  20. }
  21. LL_FOREACH(head, e) {
  22. printf("%c ", e->id);
  23. }
  24. printf("\n");
  25. printf("DL_INSERT_INORDER\n");
  26. head = NULL;
  27. for (i=0; i<15; i++) {
  28. DL_INSERT_INORDER(head, &els[i], order_desc);
  29. }
  30. DL_FOREACH(head, e) {
  31. printf("%c ", e->id);
  32. }
  33. printf("\n");
  34. printf("CDL_INSERT_INORDER\n");
  35. head = NULL;
  36. for (i=0; i<15; i++) {
  37. CDL_INSERT_INORDER(head, &els[i], order_desc);
  38. }
  39. CDL_FOREACH(head, e) {
  40. printf("%c ", e->id);
  41. }
  42. printf("\n");
  43. CDL_FOREACH2(head, e, prev) {
  44. printf("%c ", e->id);
  45. }
  46. printf("\n");
  47. return 0;
  48. }