Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define RozmiarTablicy 1000
- struct struktura
- {
- int tab[RozmiarTablicy];
- int LiczbaElementow;
- int schowek[RozmiarTablicy];
- int LiczbaKopiowanych;
- }
- ;
- void add(struct struktura* dodaj);
- void rew(struct struktura* odwroc, int min, int max);
- void sho(struct struktura* pokaz);
- void del(struct struktura* usun, int index);
- void sum(struct struktura* suma);
- int main()
- {
- struct struktura lista;
- lista.LiczbaElementow = 0;
- lista.LiczbaKopiowanych = 0;
- char akcja[4];
- scanf ("%3s", akcja);
- while(1)
- {
- if(strcmp(akcja, "ext")==0)
- break;
- else if(strcmp(akcja, "add")==0)
- add(&lista);
- else if(strcmp(akcja, "sho")==0)
- sho(&lista);
- else if(strcmp(akcja, "rew")==0)
- {
- int min;
- int max;
- scanf("%d %d", &min, &max);
- rew(&lista, min, max);
- }
- else if (strcmp(akcja, "del") == 0)
- {
- int index;
- scanf("%d", &index);
- del(&lista, index);
- }
- else if (strcmp(akcja, "sum") ==0)
- sum(&lista);
- scanf ("%3s", akcja);
- }
- }
- void add(struct struktura* dodaj)
- {
- scanf("%d", &(dodaj->tab[dodaj->LiczbaElementow]));
- dodaj->LiczbaElementow++;
- }
- void rew(struct struktura* odwroc, int min, int max)
- {
- if (min >= max)
- return;
- int tmp = odwroc->tab[min - 1];
- odwroc->tab[min - 1] = odwroc->tab[max-1];
- odwroc->tab[max - 1] = tmp;
- rew(odwroc, ++min, --max);
- }
- void sho(struct struktura* pokaz)
- {
- static int i=0;
- if(i>=pokaz->LiczbaElementow)
- {
- i=0;
- return;
- }
- printf("%d, " ,pokaz->tab[i]);
- i++;
- sho(pokaz);
- }
- void del(struct struktura* usun, int index)
- {
- if (index >= usun->LiczbaElementow)
- {
- usun->LiczbaElementow--;
- return;
- }
- usun->tab[index - 1]= usun->tab[index];
- del(usun, ++index);
- }
- void sum(struct struktura* suma)
- {
- int i;
- int j;
- scanf("%d %d", i, j);
- suma->tab[i-1]+=suma->tab[j-1];
- del(suma, j);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement