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.

73 lines
1.5KB

  1. #include <stdio.h>
  2. #include "utlist.h"
  3. typedef struct el {
  4. int id;
  5. struct el *next, *prev;
  6. } el;
  7. int main()
  8. {
  9. int i;
  10. el *head = NULL;
  11. el els[10], *e, *tmp, *tmp2;
  12. for(i=0; i<10; i++) {
  13. els[i].id=(int)'a'+i;
  14. }
  15. /* test CDL macros */
  16. printf("CDL macros\n");
  17. CDL_PREPEND(head,&els[0]);
  18. CDL_PREPEND(head,&els[1]);
  19. CDL_PREPEND(head,&els[2]);
  20. CDL_FOREACH(head,e) {
  21. printf("%c ", e->id);
  22. }
  23. /* point head to head->next */
  24. CDL_FOREACH_SAFE(head,e,tmp,tmp2) {
  25. printf("deleting %c ", e->id);
  26. CDL_DELETE(head,e);
  27. }
  28. printf("\n");
  29. if (head != NULL) {
  30. printf("non-null head\n");
  31. }
  32. /* test DL macros */
  33. printf("DL macros\n");
  34. DL_APPEND(head,&els[0]);
  35. DL_APPEND(head,&els[1]);
  36. DL_APPEND(head,&els[2]);
  37. DL_FOREACH(head,e) {
  38. printf("%c ", e->id);
  39. }
  40. DL_FOREACH_SAFE(head,e,tmp) {
  41. printf("deleting %c ", e->id);
  42. DL_DELETE(head,e);
  43. }
  44. printf("\n");
  45. if (head != NULL) {
  46. printf("non-null head\n");
  47. }
  48. /* test LL macros */
  49. printf("LL macros\n");
  50. LL_APPEND(head,&els[0]);
  51. LL_APPEND(head,&els[1]);
  52. LL_APPEND(head,&els[2]);
  53. LL_FOREACH(head,e) {
  54. printf("%c ", e->id);
  55. }
  56. LL_FOREACH_SAFE(head,e,tmp) {
  57. printf("deleting %c ", e->id);
  58. LL_DELETE(head,e);
  59. }
  60. printf("\n");
  61. if (head != NULL) {
  62. printf("non-null head\n");
  63. }
  64. return 0;
  65. }