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.

88 lines
1.8KB

  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[20], *e, *tmp, *tmp2;
  12. el *headA = NULL;
  13. el *headB = NULL;
  14. for(i=0; i<20; i++) {
  15. els[i].id=(int)'a'+i;
  16. }
  17. /* test CDL macros */
  18. printf("CDL replace elem\n");
  19. CDL_PREPEND(headA,&els[3]);
  20. CDL_PREPEND(headA,&els[2]);
  21. CDL_PREPEND(headA,&els[1]);
  22. CDL_PREPEND(headA,&els[0]);
  23. CDL_FOREACH(headA,e) {
  24. printf("%c ", e->id);
  25. }
  26. printf("\n");
  27. /* replace head elem */
  28. CDL_REPLACE_ELEM(headA, &els[0], &els[4]);
  29. CDL_FOREACH(headA,e) {
  30. printf("%c ", e->id);
  31. }
  32. printf("\n");
  33. CDL_REPLACE_ELEM(headA, &els[4], &els[5]);
  34. CDL_FOREACH(headA,e) {
  35. printf("%c ", e->id);
  36. }
  37. printf("\n");
  38. /* replace last elem */
  39. CDL_REPLACE_ELEM(headA, &els[3], &els[6]);
  40. CDL_FOREACH(headA,e) {
  41. printf("%c ", e->id);
  42. }
  43. printf("\n");
  44. CDL_REPLACE_ELEM(headA, &els[6], &els[7]);
  45. CDL_FOREACH(headA,e) {
  46. printf("%c ", e->id);
  47. }
  48. printf("\n");
  49. /* replace middle elem */
  50. CDL_REPLACE_ELEM(headA, &els[1], &els[8]);
  51. CDL_REPLACE_ELEM(headA, &els[2], &els[9]);
  52. CDL_FOREACH(headA,e) {
  53. printf("%c ", e->id);
  54. }
  55. printf("\n");
  56. /* replace all just to be sure the list is intact... */
  57. i = 10;
  58. CDL_FOREACH_SAFE(headA, e, tmp, tmp2) {
  59. CDL_REPLACE_ELEM(headA, e, &els[i]);
  60. i++;
  61. }
  62. CDL_FOREACH(headA,e) {
  63. printf("%c ", e->id);
  64. }
  65. printf("\n");
  66. /* single elem */
  67. CDL_PREPEND(headB, &els[18]);
  68. CDL_FOREACH(headB,e) {
  69. printf("%c ", e->id);
  70. }
  71. printf("\n");
  72. CDL_REPLACE_ELEM(headB, &els[18], &els[19]);
  73. CDL_FOREACH(headB,e) {
  74. printf("%c ", e->id);
  75. }
  76. printf("\n");
  77. return 0;
  78. }