Advertisement
KlimexuS

Untitled

Jan 5th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 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. void pst(struct struktura* wklej, int index_i, int index_clipboard);
  21. void shift(struct struktura* przesun, int index_l, int index_r);
  22. int check(struct struktura* sprawdz, int min, int max);
  23. int checking(struct struktura* sprawdzanie, int index);
  24.  
  25.  
  26. int main()
  27. {
  28. struct struktura lista;
  29. lista.LiczbaElementow = 0;
  30. lista.LiczbaKopiowanych = 0;
  31.  
  32. char akcja[4];
  33. scanf ("%3s", akcja);
  34. while(1)
  35. {
  36. if(strcmp(akcja, "ext")==0)
  37. break;
  38. else if(strcmp(akcja, "add")==0)
  39. add(&lista);
  40. else if(strcmp(akcja, "sho")==0)
  41. sho(&lista);
  42. else if(strcmp(akcja, "rew")==0)
  43. {
  44. int min;
  45. int max;
  46. scanf("%d %d", &min, &max);
  47. if(check(&lista, min, max))
  48. rew(&lista, min, max);
  49. else
  50. printf("nieprawidlowe dane wejsciowe\n");
  51. }
  52. else if (strcmp(akcja, "del") == 0)
  53. {
  54. int index;
  55. scanf("%d", &index);
  56. if(checking(&lista, index))
  57. del(&lista, index);
  58. else
  59. printf("nieprawidlowe dane wejsciowe\n");
  60. }
  61. else if (strcmp(akcja, "sum") ==0)
  62. sum(&lista);
  63. else if (strcmp(akcja, "cpy") ==0)
  64. {
  65.  
  66. int i;
  67. int j;
  68. scanf("%d %d", &i, &j);
  69. if(check(&lista, i, j))
  70. cpy(&lista, i, j);
  71. else
  72. printf("nieprawidlowe dane wejsciowe\n");
  73.  
  74. }
  75. else if (strcmp(akcja, "pst") == 0) {
  76. int i;
  77. scanf("%d", &i);
  78. if(checking(&lista, i))
  79. pst(&lista, i, 0);
  80. else
  81. printf("nieprawidlowe dane wejsciowe\n");
  82. }
  83.  
  84.  
  85. scanf ("%3s", akcja);
  86. }
  87.  
  88.  
  89.  
  90.  
  91. }
  92.  
  93. void add(struct struktura* dodaj)
  94. {
  95. if(dodaj->LiczbaElementow<RozmiarTablicy)
  96. {
  97. scanf("%d", &(dodaj->tab[dodaj->LiczbaElementow]));
  98. dodaj->LiczbaElementow++;
  99. }
  100. else
  101. printf("tablica jest pelna\n");
  102. }
  103.  
  104. void rew(struct struktura* odwroc, int min, int max)
  105. {
  106. if (min >= max)
  107. return;
  108. int tmp = odwroc->tab[min - 1];
  109. odwroc->tab[min - 1] = odwroc->tab[max-1];
  110. odwroc->tab[max - 1] = tmp;
  111. rew(odwroc, ++min, --max);
  112. }
  113.  
  114. void sho(struct struktura* pokaz)
  115. {
  116. static int i=0;
  117. if(i>=pokaz->LiczbaElementow)
  118. {
  119. i=0;
  120. return;
  121. }
  122. printf("%d, " ,pokaz->tab[i]);
  123. i++;
  124. sho(pokaz);
  125. }
  126. void del(struct struktura* usun, int index)
  127. {
  128. if (index >= usun->LiczbaElementow||index<=0)
  129. {
  130. printf("nieprawidlowe dane wejsciowe\n");
  131. usun->LiczbaElementow--;
  132. return;
  133. }
  134. usun->tab[index - 1]= usun->tab[index];
  135. del(usun, ++index);
  136. }
  137. void sum(struct struktura* suma)
  138. {
  139. int i;
  140. int j;
  141. scanf("%d %d", &i, &j);
  142. if(check(&suma, i, j))
  143. {
  144. suma->tab[i-1]+=suma->tab[j-1];
  145. del(suma, j);
  146. }
  147. else
  148. {
  149. printf("nieprawidlowe dane wejsciowe\n");
  150. return;
  151. }
  152. }
  153. void cpy(struct struktura* kopia, int min, int max)
  154. {
  155. if(min>max)
  156. {
  157. return;
  158. }
  159. kopia->schowek[kopia->LiczbaKopiowanych++]=kopia->tab[min-1];
  160. cpy(kopia, ++min, max);
  161. }
  162.  
  163. void pst(struct struktura* wklej, int index_i, int index_clipboard) {
  164. int static flag = 1;
  165. if (index_clipboard > RozmiarTablicy || index_clipboard > wklej->LiczbaKopiowanych-1) {
  166. flag = 1;
  167. return;
  168. }
  169. if (flag)
  170. {
  171. shift(wklej, index_i, wklej->LiczbaElementow);
  172. wklej->LiczbaElementow += wklej->LiczbaKopiowanych;
  173. flag = 0;
  174. }
  175. wklej->tab[index_i - 1] = wklej->schowek[index_clipboard++];
  176. pst(wklej, ++index_i, index_clipboard);
  177. }
  178.  
  179. void shift(struct struktura* przesun, int index_l, int index_r)
  180. {
  181. if (index_r < index_l || index_r-1+przesun->LiczbaKopiowanych > RozmiarTablicy)
  182. {
  183. return;
  184. }
  185. przesun->tab[index_r - 1 + przesun->LiczbaKopiowanych] = przesun->tab[index_r - 1];
  186. shift(przesun, index_l, --index_r);
  187. }
  188. int check(struct struktura* sprawdz, int min, int max)
  189. {
  190. if(min<=0 || max<=0 || min>sprawdz->LiczbaElementow || max>sprawdz->LiczbaElementow)
  191. return 0;
  192. else
  193. return 1;
  194. }
  195. int checking(struct struktura* sprawdzanie, int index)
  196. {
  197. if(index<=0 || index>sprawdzanie->LiczbaElementow)
  198. return 0;
  199. else
  200. return 1;
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement