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.

94 lines
2.0KB

  1. #include <stdio.h>
  2. #include "utlist.h"
  3. typedef struct el {
  4. int id, score;
  5. struct el *next, *prev;
  6. struct el *next_list2, *prev_list2;
  7. } el;
  8. static int order_desc(el *a, el *b)
  9. {
  10. return (a->score > b->score) ? -1 : (a->score < b->score);
  11. }
  12. static int order_asc(el *a, el *b)
  13. {
  14. return -order_desc(a, b);
  15. }
  16. int main()
  17. {
  18. int i;
  19. el *head = NULL;
  20. el *head2 = NULL;
  21. el els[15], *e;
  22. for (i=0; i<15; i++) {
  23. els[i].id = (int)'a'+i;
  24. els[i].score = i%7;
  25. LL_INSERT_INORDER(head, &els[i], order_desc);
  26. LL_INSERT_INORDER2(head2, &els[i], order_asc, next_list2);
  27. }
  28. printf("LL_INSERT_INORDER\n");
  29. printf("list1: ");
  30. LL_FOREACH(head, e) {
  31. printf("%c ", e->id);
  32. }
  33. printf("\n");
  34. printf("list2: ");
  35. LL_FOREACH2(head2, e, next_list2) {
  36. printf("%c ", e->id);
  37. }
  38. printf("\n");
  39. printf("DL_INSERT_INORDER\n");
  40. head = NULL;
  41. head2 = NULL;
  42. for (i=0; i<15; i++) {
  43. DL_INSERT_INORDER(head, &els[i], order_desc);
  44. DL_INSERT_INORDER2(head2, &els[i], order_asc, prev_list2, next_list2);
  45. }
  46. printf("list1: ");
  47. DL_FOREACH(head, e) {
  48. printf("%c ", e->id);
  49. }
  50. printf("\n");
  51. printf("list2: ");
  52. DL_FOREACH2(head2, e, next_list2) {
  53. printf("%c ", e->id);
  54. }
  55. printf("\n");
  56. printf("CDL_INSERT_INORDER\n");
  57. head = NULL;
  58. head2 = NULL;
  59. for (i=0; i<15; i++) {
  60. CDL_INSERT_INORDER(head, &els[i], order_desc);
  61. CDL_INSERT_INORDER2(head2, &els[i], order_asc, prev_list2, next_list2);
  62. }
  63. printf("list1:\n");
  64. CDL_FOREACH(head, e) {
  65. printf("%c ", e->id);
  66. }
  67. printf("\n");
  68. CDL_FOREACH2(head, e, prev) {
  69. printf("%c ", e->id);
  70. }
  71. printf("\n");
  72. printf("list2:\n");
  73. CDL_FOREACH2(head2, e, next_list2) {
  74. printf("%c ", e->id);
  75. }
  76. printf("\n");
  77. CDL_FOREACH2(head2, e, prev_list2) {
  78. printf("%c ", e->id);
  79. }
  80. printf("\n");
  81. return 0;
  82. }