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.

67 lines
1.5KB

  1. #include <stdio.h>
  2. #include "utarray.h"
  3. static int reverse(const void *a, const void *b)
  4. {
  5. int _a = *(const int*)a;
  6. int _b = *(const int*)b;
  7. return _b - _a;
  8. }
  9. int main()
  10. {
  11. UT_array *a;
  12. int i, *p;
  13. utarray_new(a, &ut_int_icd);
  14. for(i=0; i<10; i++) {
  15. utarray_push_back(a,&i);
  16. }
  17. for(p=(int*)utarray_front(a); p!=NULL; p=(int*)utarray_next(a,p)) {
  18. printf("%d ",*p);
  19. }
  20. printf("\n");
  21. utarray_sort(a,reverse);
  22. while ( (p=(int*)utarray_next(a,p)) != NULL ) {
  23. printf("%d ", *p);
  24. }
  25. printf("\n");
  26. utarray_erase(a,3,3);
  27. while ( (p=(int*)utarray_next(a,p)) != NULL ) {
  28. printf("%d ", *p);
  29. }
  30. printf("\n");
  31. utarray_erase(a,1,2);
  32. while ( (p=(int*)utarray_next(a,p)) != NULL ) {
  33. printf("%d ", *p);
  34. }
  35. printf("\n");
  36. utarray_erase(a,0,1);
  37. while ( (p=(int*)utarray_next(a,p)) != NULL ) {
  38. printf("%d ", *p);
  39. }
  40. printf("\n");
  41. utarray_erase(a,3,1);
  42. while ( (p=(int*)utarray_next(a,p)) != NULL ) {
  43. printf("%d ", *p);
  44. }
  45. printf("\n");
  46. utarray_resize(a,5);
  47. while ( (p=(int*)utarray_next(a,p)) != NULL ) {
  48. printf("%d ", *p);
  49. }
  50. printf("\n");
  51. utarray_resize(a,3);
  52. while ( (p=(int*)utarray_next(a,p)) != NULL ) {
  53. printf("%d ", *p);
  54. }
  55. printf("\n");
  56. utarray_erase(a,0,3);
  57. while ( (p=(int*)utarray_next(a,p)) != NULL ) {
  58. printf("%d ", *p);
  59. }
  60. printf("\n");
  61. utarray_free(a);
  62. return 0;
  63. }