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.

93 lines
1.9KB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "utlist.h"
  4. typedef struct el {
  5. int id;
  6. struct el *next, *prev;
  7. } el;
  8. int main()
  9. {
  10. int i;
  11. el els[26], *e, *tmp;
  12. el *headA = NULL;
  13. el *headB = NULL;
  14. for(i=0; i<25; i++) {
  15. els[i].id=(int)'a'+i;
  16. }
  17. /* test DL macros */
  18. printf("DL prepend elem\n");
  19. DL_APPEND(headA,&els[0]);
  20. DL_APPEND(headA,&els[1]);
  21. DL_APPEND(headA,&els[2]);
  22. DL_APPEND(headA,&els[3]);
  23. DL_FOREACH(headA,e) {
  24. printf("%c ", e->id);
  25. }
  26. printf("\n");
  27. /* prepend head elem */
  28. DL_PREPEND_ELEM(headA, &els[0], &els[4]);
  29. DL_FOREACH(headA,e) {
  30. printf("%c ", e->id);
  31. }
  32. printf("\n");
  33. DL_PREPEND_ELEM(headA, &els[4], &els[5]);
  34. DL_FOREACH(headA,e) {
  35. printf("%c ", e->id);
  36. }
  37. printf("\n");
  38. /* prepend last elem */
  39. DL_PREPEND_ELEM(headA, &els[3], &els[6]);
  40. DL_FOREACH(headA,e) {
  41. printf("%c ", e->id);
  42. }
  43. printf("\n");
  44. DL_PREPEND_ELEM(headA, &els[6], &els[7]);
  45. DL_FOREACH(headA,e) {
  46. printf("%c ", e->id);
  47. }
  48. printf("\n");
  49. /* prepend middle elem */
  50. DL_PREPEND_ELEM(headA, &els[2], &els[8]);
  51. DL_PREPEND_ELEM(headA, &els[2], &els[9]);
  52. DL_FOREACH(headA,e) {
  53. printf("%c ", e->id);
  54. }
  55. printf("\n");
  56. /* prepend all just to be sure the list is intact... */
  57. i = 10;
  58. DL_FOREACH_SAFE(headA, e, tmp) {
  59. DL_PREPEND_ELEM(headA, e, &els[i]);
  60. i++;
  61. }
  62. DL_FOREACH(headA,e) {
  63. printf("%c ", e->id);
  64. }
  65. printf("\n");
  66. /* single elem */
  67. DL_APPEND(headB, &els[20]);
  68. DL_FOREACH(headB,e) {
  69. printf("%c ", e->id);
  70. }
  71. printf("\n");
  72. DL_PREPEND_ELEM(headB, &els[20], &els[21]);
  73. DL_FOREACH(headB,e) {
  74. printf("%c ", e->id);
  75. }
  76. printf("\n");
  77. DL_PREPEND_ELEM(headB, &els[21], &els[22]);
  78. DL_FOREACH(headB,e) {
  79. printf("%c ", e->id);
  80. }
  81. printf("\n");
  82. return 0;
  83. }