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.

85 lines
2.1KB

  1. #include <stdio.h>
  2. #include "utarray.h"
  3. static int strsort(const void *_a, const void *_b)
  4. {
  5. const char *a = *(const char* const *)_a;
  6. const char *b = *(const char* const *)_b;
  7. return strcmp(a,b);
  8. }
  9. static int revsort(const void *_a, const void *_b)
  10. {
  11. const char *a = *(const char* const *)_a;
  12. const char *b = *(const char* const *)_b;
  13. return strcmp(b,a);
  14. }
  15. int main()
  16. {
  17. UT_array *strs,*strs2;
  18. char *s, **p=NULL;
  19. utarray_new(strs, &ut_str_icd);
  20. s=(char*)"hello";
  21. utarray_push_back(strs, &s);
  22. s=(char*)"world";
  23. utarray_push_back(strs, &s);
  24. while ( (p=(char**)utarray_next(strs,p)) != NULL ) {
  25. printf("%s ",*p);
  26. }
  27. printf("\n");
  28. s=(char*)"begin";
  29. utarray_insert(strs,&s,0);
  30. while ( (p=(char**)utarray_next(strs,p)) != NULL ) {
  31. printf("%s ",*p);
  32. }
  33. printf("\n");
  34. utarray_new(strs2, &ut_str_icd);
  35. s=(char*)"alt";
  36. utarray_push_back(strs2, &s);
  37. s=(char*)"oth";
  38. utarray_push_back(strs2, &s);
  39. utarray_inserta(strs2, strs, 1);
  40. while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
  41. printf("%s ",*p);
  42. }
  43. printf("\n");
  44. utarray_erase(strs2,0,2);
  45. while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
  46. printf("%s ",*p);
  47. }
  48. printf("\n");
  49. utarray_pop_back(strs2);
  50. while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
  51. printf("%s ",*p);
  52. }
  53. printf("\n");
  54. utarray_concat(strs2, strs);
  55. while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
  56. printf("%s ",*p);
  57. }
  58. printf("\n");
  59. utarray_clear(strs2);
  60. utarray_concat(strs2, strs);
  61. while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
  62. printf("%s ",*p);
  63. }
  64. printf("\n");
  65. printf("sorting strs2\n");
  66. utarray_sort(strs2,strsort);
  67. while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
  68. printf("%s ",*p);
  69. }
  70. printf("\n");
  71. printf("reverse sorting strs2\n");
  72. utarray_sort(strs2,revsort);
  73. while ( (p=(char**)utarray_next(strs2,p)) != NULL ) {
  74. printf("%s ",*p);
  75. }
  76. printf("\n");
  77. utarray_clear(strs2);
  78. utarray_free(strs2);
  79. utarray_free(strs);
  80. return 0;
  81. }