Advertisement
KlimexuS

Untitled

Jan 5th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define RozmiarTablicy 1000
  4.  
  5. struct struktura
  6. {
  7. int tab[RozmiarTablicy];
  8. int LiczbaElementow;
  9. int schowek[RozmiarTablicy];
  10. int LiczbaKopiowanych;
  11. }
  12. ;
  13.  
  14. void add(struct struktura* dodaj);
  15. void rew(struct struktura* odwroc, int min, int max);
  16. void sho(struct struktura* pokaz);
  17. void del(struct struktura* usun, int index);
  18. void sum(struct struktura* suma);
  19. void cpy(struct struktura* kopia, int min, int max);
  20.  
  21.  
  22.  
  23. int main()
  24. {
  25. struct struktura lista;
  26. lista.LiczbaElementow = 0;
  27. lista.LiczbaKopiowanych = 0;
  28.  
  29. char akcja[4];
  30. scanf ("%3s", akcja);
  31. while(1)
  32. {
  33. if(strcmp(akcja, "ext")==0)
  34. break;
  35. else if(strcmp(akcja, "add")==0)
  36. add(&lista);
  37. else if(strcmp(akcja, "sho")==0)
  38. sho(&lista);
  39. else if(strcmp(akcja, "rew")==0)
  40. {
  41. int min;
  42. int max;
  43. scanf("%d %d", &min, &max);
  44. rew(&lista, min, max);
  45. }
  46. else if (strcmp(akcja, "del") == 0)
  47. {
  48. int index;
  49. scanf("%d", &index);
  50. del(&lista, index);
  51. }
  52. else if (strcmp(akcja, "sum") ==0)
  53. sum(&lista);
  54. else if (strcmp(akcja, "cpy") ==0)
  55. int i;
  56. int j;
  57. scanf("%d %d", &i, &j);
  58. cpy(&lista, i, j);
  59.  
  60.  
  61.  
  62. scanf ("%3s", akcja);
  63. }
  64.  
  65.  
  66.  
  67.  
  68. }
  69.  
  70. void add(struct struktura* dodaj)
  71. {
  72. scanf("%d", &(dodaj->tab[dodaj->LiczbaElementow]));
  73. dodaj->LiczbaElementow++;
  74. }
  75.  
  76. void rew(struct struktura* odwroc, int min, int max)
  77. {
  78. if (min >= max)
  79. return;
  80. int tmp = odwroc->tab[min - 1];
  81. odwroc->tab[min - 1] = odwroc->tab[max-1];
  82. odwroc->tab[max - 1] = tmp;
  83. rew(odwroc, ++min, --max);
  84. }
  85.  
  86. void sho(struct struktura* pokaz)
  87. {
  88. static int i=0;
  89. if(i>=pokaz->LiczbaElementow)
  90. {
  91. i=0;
  92. return;
  93. }
  94. printf("%d, " ,pokaz->tab[i]);
  95. i++;
  96. sho(pokaz);
  97. }
  98. void del(struct struktura* usun, int index)
  99. {
  100. if (index >= usun->LiczbaElementow)
  101. {
  102. usun->LiczbaElementow--;
  103. return;
  104. }
  105. usun->tab[index - 1]= usun->tab[index];
  106. del(usun, ++index);
  107. }
  108. void sum(struct struktura* suma)
  109. {
  110. int i;
  111. int j;
  112. scanf("%d %d", &i, &j);
  113. suma->tab[i-1]+=suma->tab[j-1];
  114. del(suma, j);
  115. }
  116. void cpy(struct struktura* kopia, int min, int max)
  117. {
  118. if(min>max)
  119. return;
  120. kopia->schowek[kopia->LiczbaKopiowanych++]=kopia->tab[min-1];
  121. cpy(kopia, ++min, max);
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement