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);
- void cpy(struct struktura* kopia, int min, int max);
- void pst(struct struktura* wklej, int index_i, int index_clipboard);
- void shift(struct struktura* przesun, int index_l, int index_r);
- int check(struct struktura* sprawdz, int min, int max);
- int checking(struct struktura* sprawdzanie, int index);
- 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);
- if(check(&lista, min, max))
- rew(&lista, min, max);
- else
- printf("nieprawidlowe dane wejsciowe\n");
- }
- else if (strcmp(akcja, "del") == 0)
- {
- int index;
- scanf("%d", &index);
- if(checking(&lista, index))
- del(&lista, index);
- else
- printf("nieprawidlowe dane wejsciowe\n");
- }
- else if (strcmp(akcja, "sum") ==0)
- sum(&lista);
- else if (strcmp(akcja, "cpy") ==0)
- {
- int i;
- int j;
- scanf("%d %d", &i, &j);
- if(check(&lista, i, j))
- cpy(&lista, i, j);
- else
- printf("nieprawidlowe dane wejsciowe\n");
- }
- else if (strcmp(akcja, "pst") == 0) {
- int i;
- scanf("%d", &i);
- if(checking(&lista, i))
- pst(&lista, i, 0);
- else
- printf("nieprawidlowe dane wejsciowe\n");
- }
- scanf ("%3s", akcja);
- }
- }
- void add(struct struktura* dodaj)
- {
- if(dodaj->LiczbaElementow<RozmiarTablicy)
- {
- scanf("%d", &(dodaj->tab[dodaj->LiczbaElementow]));
- dodaj->LiczbaElementow++;
- }
- else
- printf("tablica jest pelna\n");
- }
- 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||index<=0)
- {
- printf("nieprawidlowe dane wejsciowe\n");
- 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);
- if(check(&suma, i, j))
- {
- suma->tab[i-1]+=suma->tab[j-1];
- del(suma, j);
- }
- else
- {
- printf("nieprawidlowe dane wejsciowe\n");
- return;
- }
- }
- void cpy(struct struktura* kopia, int min, int max)
- {
- if(min>max)
- {
- return;
- }
- kopia->schowek[kopia->LiczbaKopiowanych++]=kopia->tab[min-1];
- cpy(kopia, ++min, max);
- }
- void pst(struct struktura* wklej, int index_i, int index_clipboard) {
- int static flag = 1;
- if (index_clipboard > RozmiarTablicy || index_clipboard > wklej->LiczbaKopiowanych-1) {
- flag = 1;
- return;
- }
- if (flag)
- {
- shift(wklej, index_i, wklej->LiczbaElementow);
- wklej->LiczbaElementow += wklej->LiczbaKopiowanych;
- flag = 0;
- }
- wklej->tab[index_i - 1] = wklej->schowek[index_clipboard++];
- pst(wklej, ++index_i, index_clipboard);
- }
- void shift(struct struktura* przesun, int index_l, int index_r)
- {
- if (index_r < index_l || index_r-1+przesun->LiczbaKopiowanych > RozmiarTablicy)
- {
- return;
- }
- przesun->tab[index_r - 1 + przesun->LiczbaKopiowanych] = przesun->tab[index_r - 1];
- shift(przesun, index_l, --index_r);
- }
- int check(struct struktura* sprawdz, int min, int max)
- {
- if(min<=0 || max<=0 || min>sprawdz->LiczbaElementow || max>sprawdz->LiczbaElementow)
- return 0;
- else
- return 1;
- }
- int checking(struct struktura* sprawdzanie, int index)
- {
- if(index<=0 || index>sprawdzanie->LiczbaElementow)
- return 0;
- else
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement