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.

91 lines
1.9KB

  1. #include <stdio.h>
  2. #include "utlist.h"
  3. typedef struct el {
  4. int id;
  5. struct el *next, *prev;
  6. } el;
  7. static int eltcmp(el *a, el *b)
  8. {
  9. return a->id - b->id;
  10. }
  11. int main()
  12. {
  13. int i;
  14. el *head = NULL;
  15. el els[10], *e, *tmp, *tmp2;
  16. for(i=0; i<10; i++) {
  17. els[i].id=(int)'a'+i;
  18. }
  19. /* test LL macros */
  20. printf("LL macros\n");
  21. LL_APPEND(head,&els[0]);
  22. LL_APPEND(head,&els[1]);
  23. LL_APPEND(head,&els[2]);
  24. LL_FOREACH(head,e) {
  25. printf("%c ", e->id);
  26. }
  27. printf("\n");
  28. LL_SEARCH_SCALAR(head, e, id, 'b');
  29. if (e != NULL) {
  30. printf("search scalar found b\n");
  31. }
  32. LL_SEARCH(head, e, &els[0], eltcmp);
  33. if (e != NULL) {
  34. printf("search found %c\n",e->id);
  35. }
  36. LL_FOREACH_SAFE(head,e,tmp) {
  37. LL_DELETE(head,e);
  38. }
  39. printf("\n");
  40. /* test DL macros */
  41. printf("DL macros\n");
  42. DL_APPEND(head,&els[0]);
  43. DL_APPEND(head,&els[1]);
  44. DL_APPEND(head,&els[2]);
  45. DL_FOREACH(head,e) {
  46. printf("%c ", e->id);
  47. }
  48. printf("\n");
  49. DL_SEARCH_SCALAR(head, e, id, 'b');
  50. if (e != NULL) {
  51. printf("search scalar found b\n");
  52. }
  53. DL_SEARCH(head, e, &els[0], eltcmp);
  54. if (e != NULL) {
  55. printf("search found %c\n",e->id);
  56. }
  57. DL_FOREACH_SAFE(head,e,tmp) {
  58. DL_DELETE(head,e);
  59. }
  60. printf("\n");
  61. /* test CDL macros */
  62. printf("CDL macros\n");
  63. CDL_PREPEND(head,&els[0]);
  64. CDL_PREPEND(head,&els[1]);
  65. CDL_PREPEND(head,&els[2]);
  66. CDL_FOREACH(head,e) {
  67. printf("%c ", e->id);
  68. }
  69. printf("\n");
  70. CDL_SEARCH_SCALAR(head, e, id, 'b');
  71. if (e != NULL) {
  72. printf("search scalar found b\n");
  73. }
  74. CDL_SEARCH(head, e, &els[0], eltcmp);
  75. if (e != NULL) {
  76. printf("search found %c\n",e->id);
  77. }
  78. CDL_FOREACH_SAFE(head,e,tmp,tmp2) {
  79. CDL_DELETE(head,e);
  80. }
  81. return 0;
  82. }