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.

131 lines
4.0KB

  1. #include <stdio.h>
  2. #include "utarray.h"
  3. typedef struct {
  4. int a;
  5. int b;
  6. } intpair_t;
  7. int main()
  8. {
  9. UT_array *pairs, *pairs_cpy;
  10. intpair_t it, *ip;
  11. UT_icd pairicd = { sizeof(intpair_t),NULL,NULL,NULL};
  12. size_t zero=0;
  13. utarray_new(pairs, &pairicd);
  14. printf("length is %u\n", utarray_len(pairs));
  15. it.a = 1;
  16. it.b=2;
  17. utarray_push_back(pairs, &it);
  18. printf("push\n");
  19. printf("length is %u\n", utarray_len(pairs));
  20. ip = (intpair_t*)utarray_back(pairs);
  21. printf("back is %d %d\n", ip->a, ip->b);
  22. utarray_pop_back(pairs);
  23. printf("pop\n");
  24. printf("length is %u\n", utarray_len(pairs));
  25. it.a = 1;
  26. it.b=2;
  27. utarray_push_back(pairs, &it);
  28. printf("push\n");
  29. it.a = 3;
  30. it.b=4;
  31. utarray_push_back(pairs, &it);
  32. printf("push\n");
  33. printf("length is %u\n", utarray_len(pairs));
  34. ip=NULL;
  35. while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
  36. printf("%d %d\n", ip->a, ip->b);
  37. }
  38. utarray_erase(pairs,0,1);
  39. printf("erase [0]\n");
  40. printf("length is %u\n", utarray_len(pairs));
  41. while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
  42. printf("%d %d\n", ip->a, ip->b);
  43. }
  44. it.a = 1;
  45. it.b=2;
  46. utarray_push_back(pairs, &it);
  47. printf("push\n");
  48. while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
  49. printf("%d %d\n", ip->a, ip->b);
  50. }
  51. utarray_clear(pairs);
  52. printf("clear\n");
  53. printf("length is %u\n", utarray_len(pairs));
  54. utarray_extend_back(pairs);
  55. printf("extend\n");
  56. ip = (intpair_t*)utarray_back(pairs);
  57. printf("length is %u\n", utarray_len(pairs));
  58. printf("ip points to [0] ? %s\n", (ip==(intpair_t*)utarray_front(pairs)) ? "yes" : "no");
  59. it.a = 1;
  60. it.b=2;
  61. utarray_push_back(pairs, &it);
  62. printf("push\n");
  63. ip=NULL;
  64. while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
  65. printf("%d %d\n", ip->a, ip->b);
  66. }
  67. utarray_erase(pairs,1,1);
  68. printf("erase [1]\n");
  69. printf("length is %u\n", utarray_len(pairs));
  70. while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
  71. printf("%d %d\n", ip->a, ip->b);
  72. }
  73. it.a = 3;
  74. it.b=4;
  75. utarray_push_back(pairs, &it);
  76. printf("push\n");
  77. for(ip=(intpair_t*)utarray_front(pairs); ip!=NULL; ip=(intpair_t*)utarray_next(pairs,ip)) {
  78. printf("%d %d\n", ip->a,ip->b);
  79. }
  80. ip = (intpair_t*)utarray_back(pairs);
  81. printf("back is %d %d\n", ip->a, ip->b);
  82. utarray_new(pairs_cpy, &pairicd);
  83. utarray_concat(pairs_cpy, pairs);
  84. printf("copy\n");
  85. printf("cpy length is %u\n", utarray_len(pairs_cpy));
  86. ip=NULL;
  87. while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) {
  88. printf("cpy %d %d\n", ip->a, ip->b);
  89. }
  90. it.a=5;
  91. it.b=6;
  92. utarray_insert(pairs_cpy, &it, 0);
  93. printf("insert cpy[0]\n");
  94. printf("cpy length is %u\n", utarray_len(pairs_cpy));
  95. while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) {
  96. printf("cpy %d %d\n", ip->a, ip->b);
  97. }
  98. utarray_erase(pairs_cpy,0,2);
  99. printf("erase cpy [0] [1]\n");
  100. printf("cpy length is %u\n", utarray_len(pairs_cpy));
  101. while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) {
  102. printf("cpy %d %d\n", ip->a, ip->b);
  103. }
  104. utarray_inserta(pairs_cpy, pairs, 1);
  105. printf("inserta at cpy[1]\n");
  106. printf("cpy length is %u\n", utarray_len(pairs_cpy));
  107. while( (ip=(intpair_t*)utarray_next(pairs_cpy,ip)) != NULL ) {
  108. printf("cpy %d %d\n", ip->a, ip->b);
  109. }
  110. utarray_free(pairs_cpy);
  111. printf("free cpy\n");
  112. printf("length is %u\n", utarray_len(pairs));
  113. utarray_resize(pairs, 30);
  114. printf("resize to 30\n");
  115. printf("length is %u\n", utarray_len(pairs));
  116. while( (ip=(intpair_t*)utarray_next(pairs,ip)) != NULL ) {
  117. printf("%d %d\n", ip->a, ip->b);
  118. }
  119. utarray_resize(pairs, 1);
  120. printf("resize to 1\n");
  121. printf("length is %u\n", utarray_len(pairs));
  122. utarray_resize(pairs, zero);
  123. printf("resize to 0\n");
  124. printf("length is %u\n", utarray_len(pairs));
  125. utarray_free(pairs);
  126. printf("free\n");
  127. return 0;
  128. }