Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <stdio.h>
- #include <time.h>
- #include <utility>
- #include <cstdio>
- using namespace std;
- //int *rosnacy = new int[rozmiar];
- int i=0;
- int *tabrosnacy;
- int *tabprzysty;
- struct listajednokierunkowa{
- int wartoscciagu;
- listajednokierunkowa *next;
- }*zmienna;
- struct listajednokierunkowa *head = NULL;
- struct listajednokierunkowa *pierwszyel = NULL;
- struct listajednokierunkowa *pomocnik = NULL;
- struct listajednokierunkowa *ostatniel = NULL;
- void wyczyscliste()
- {
- head=pierwszyel;
- while(head->next!=NULL)
- {
- pomocnik=head->next;
- head=NULL;
- head=pomocnik;
- }
- pierwszyel=NULL;
- }
- void dodawaniedolisty(int rozmiar)
- {
- listajednokierunkowa *element = new listajednokierunkowa;
- head=pierwszyel;
- while(head->next!=NULL)
- {
- pomocnik=head->next;
- head=pomocnik;
- }
- for(int x=0;x<rozmiar;x++)
- {
- element->next=NULL;
- element->wartoscciagu=tabprzysty[x];
- head->next=element;
- head=element;
- head->next=NULL;
- ostatniel=head;
- /* element->next=NULL;
- element->wartoscciagu=tabprzysty[x];
- head=element;
- head->next=element;
- head=head->next;
- ostatniel=head;*/
- }
- /* for(int x=0;x<rozmiar;x++)
- {
- head=ostatniel;
- element->next=NULL;
- element->wartoscciagu=tabprzysty[x];
- //cout<<"TTT";
- i++;
- //cout<<element->wartoscciagu;
- //cout<<"\n";
- //head=element;
- head->next=element;
- head=element;
- ostatniel=head;
- }*/
- //cout<<"\n";
- //cout<<head->wartoscciagu;
- //cout<<"\n";
- }
- void usuwaniezlisty(int rozmiar)
- { int x;
- head=pierwszyel;
- while(head->next!=NULL)
- {
- pomocnik=head->next;
- for(int i=0;i<rozmiar; i++)
- {
- x=tabprzysty[i];
- if(head->wartoscciagu==x)
- {
- head=NULL;
- }
- }
- head=pomocnik;
- }
- }
- void stworzliste()
- {
- listajednokierunkowa *element = new listajednokierunkowa;
- if(pierwszyel==NULL)
- {
- element->wartoscciagu=tabrosnacy[i];
- i++;
- //cout<<element->wartoscciagu;
- //cout<<"\n";
- element->next=NULL;
- head=element;
- pierwszyel=head;
- }
- /* if(i==1)
- {
- head=head->next;
- head->wartoscciagu=tabrosnacy[i];
- head->next=NULL;
- pierwszyel->next=head;
- }*/
- else
- {
- element->next=NULL;
- element->wartoscciagu=tabrosnacy[i];
- //cout<<"TTT";
- i++;
- //cout<<element->wartoscciagu;
- //cout<<"\n";
- //head=element;
- head->next=element;
- head=element;
- ostatniel=head;
- }
- }
- void rosnace(int rozmiar)
- {
- tabrosnacy = new int[rozmiar];
- int j = 1;
- for (int i = 0; i < rozmiar; i++)
- {
- tabrosnacy[i] = j;
- j += 2;
- }
- //cout << endl << "CIAG ROSNACY" << endl;
- //for (int k = 0; k < rozmiar; k++)
- //cout << tab[k] << " | ";
- }
- void parzyste(int rozmiar)
- {
- tabprzysty = new int[rozmiar];
- for (int i = 0; i < rozmiar; i++)
- {
- int j=rand();
- while(j%2!=0)
- {
- j=rand();
- }
- tabprzysty[i] = j;
- }
- //cout << endl << "CIAG ROSNACY" << endl;
- //for (int k = 0; k < rozmiar; k++)
- //cout << tab[k] << " | ";
- }
- int main()
- {
- clock_t t;
- int rozmiarrosn=100000;
- for(int x1=0; x1<20; x1++)
- {
- rosnace(rozmiarrosn);
- parzyste(rozmiarrosn);
- t = clock();
- for(int x=0;x<rozmiarrosn;x++)
- {
- stworzliste();
- }
- t = clock() - t;
- printf("%fs STWORZENIE LISTY\n",((float)t)/CLOCKS_PER_SEC);
- t = clock();
- usuwaniezlisty(rozmiarrosn/100);
- t = clock() - t;
- printf("%fs USUNIECIE ELEMENTOW Z LISTY\n",((float)t)/CLOCKS_PER_SEC);
- t = clock();
- dodawaniedolisty(rozmiarrosn/100);
- t = clock() - t;
- printf("%fs DODAWANIE DO LISTY\n",((float)t)/CLOCKS_PER_SEC);
- wyczyscliste();
- i=0;
- rozmiarrosn=rozmiarrosn+10000;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement