Advertisement
KlimexuS

Untitled

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