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;
  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 LL macros */
  18. printf("LL replace elem\n");
  19. LL_APPEND(headA,&els[0]);
  20. LL_APPEND(headA,&els[1]);
  21. LL_APPEND(headA,&els[2]);
  22. LL_APPEND(headA,&els[3]);
  23. LL_FOREACH(headA,e) {
  24. printf("%c ", e->id);
  25. }
  26. printf("\n");
  27. /* replace head elem */
  28. LL_REPLACE_ELEM(headA, &els[0], &els[4]);
  29. LL_FOREACH(headA,e) {
  30. printf("%c ", e->id);
  31. }
  32. printf("\n");
  33. LL_REPLACE_ELEM(headA, &els[4], &els[5]);
  34. LL_FOREACH(headA,e) {
  35. printf("%c ", e->id);
  36. }
  37. printf("\n");
  38. /* replace last elem */
  39. LL_REPLACE_ELEM(headA, &els[3], &els[6]);
  40. LL_FOREACH(headA,e) {
  41. printf("%c ", e->id);
  42. }
  43. printf("\n");
  44. LL_REPLACE_ELEM(headA, &els[6], &els[7]);
  45. LL_FOREACH(headA,e) {
  46. printf("%c ", e->id);
  47. }
  48. printf("\n");
  49. /* replace middle elem */
  50. LL_REPLACE_ELEM(headA, &els[1], &els[8]);
  51. LL_REPLACE_ELEM(headA, &els[2], &els[9]);
  52. LL_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. LL_FOREACH_SAFE(headA, e, tmp) {
  59. LL_REPLACE_ELEM(headA, e, &els[i]);
  60. i++;
  61. }
  62. LL_FOREACH(headA,e) {
  63. printf("%c ", e->id);
  64. }
  65. printf("\n");
  66. /* single elem */
  67. LL_APPEND(headB, &els[18]);
  68. LL_FOREACH(headB,e) {
  69. printf("%c ", e->id);
  70. }
  71. printf("\n");
  72. LL_REPLACE_ELEM(headB, &els[18], &els[19]);
  73. LL_FOREACH(headB,e) {
  74. printf("%c ", e->id);
  75. }
  76. printf("\n");
  77. return 0;
  78. }