Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "lista.h"
- #include <iostream>
- #include <time.h>
- #include <cstdlib>
- #include <stdio.h>
- #include <stdlib.h>
- using namespace std;
- struct object
- {
- int field1;
- char field2;
- };
- ostream& operator<<(ostream& out, const object& o)
- {
- return out << o.field1 << " " << o.field2;
- }
- int difference(object so1, object so2)
- {
- int diff = so1.field1 - so2.field1;
- if (diff != 0)
- {
- return diff;
- }
- return so1.field2 - so2.field2;
- }
- int main()
- {
- srand(time(NULL));
- Lista < object > ll;
- object so;
- clock_t t1 = clock();
- for (int i = 0; i < 100000; i++)
- {
- so.field1 = rand() % 10001;
- so.field2 = rand() % 26 + 'A';
- ll.push_back(so);
- }
- clock_t t2 = clock();
- double time = (t2 - t1) / (double)CLOCKS_PER_SEC;
- cout << "Czas dodawania 100000 elementow z przodu: " << time << endl;
- t1 = clock();
- for (int i = 0; i < 100000; i++)
- {
- so.field1 = rand() % 10001;
- so.field2 = rand() % 26 + 'A';
- ll.push_front(so);
- }
- t2 = clock();
- time = (t2 - t1) / (double)CLOCKS_PER_SEC;
- cout << "Czas dodawania 100000 elementow z tylu: " << time << endl;
- t1 = clock();
- for (int i = 0; i < 10000; i++)
- {
- ll.remove_back();
- }
- t2 = clock();
- time = (t2 - t1) / (double)CLOCKS_PER_SEC;
- cout << "Czas usuwania 10000 elementow z tylu: " << time << endl;
- t1 = clock();
- for (int i = 0; i < 10000; i++)
- {
- ll.remove_front();
- }
- t2 = clock();
- time = (t2 - t1) / (double)CLOCKS_PER_SEC;
- cout << "Czas usuwania 10000 elementow z przodu: " << time << endl;
- so.field1 = 23;
- so.field2 = 'B';
- object ao;
- ao.field1 = 25;
- ao.field2 = 'M';
- ll.print(5);
- ll.return_by_index(15);
- ll.replace(10000, so);
- t1 = clock();
- ll.search(so,*difference);
- t2 = clock();
- time = (t2 - t1) / (double)CLOCKS_PER_SEC;
- cout << "Czas wyszukiwania elementu po wartosci: " << time << endl;
- ll.print(8);
- t1 = clock();
- ll.remove_by_value(so,*difference);
- t2 = clock();
- time = (t2 - t1) / (double)CLOCKS_PER_SEC;
- cout << "Czas usuwania elementu po wartosci: " << time << endl;
- ll.remove_by_value(ao,*difference);
- ll.print(9);
- ll.insert(2, ao);
- ll.print(4);
- t1 = clock();
- ll.clear();
- t2 = clock();
- time = (t2 - t1) / (double)CLOCKS_PER_SEC;
- cout << "Czas usuwania calej listy: " << time << endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement