Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #include "lista.h"
  2. #include <iostream>
  3. #include <time.h>
  4. #include <cstdlib>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. using namespace std;
  9.  
  10. struct object
  11. {
  12. int field1;
  13. char field2;
  14. };
  15.  
  16. ostream& operator<<(ostream& out, const object& o)
  17. {
  18. return out << o.field1 << " " << o.field2;
  19. }
  20.  
  21. int difference(object so1, object so2)
  22. {
  23. int diff = so1.field1 - so2.field1;
  24.  
  25. if (diff != 0)
  26. {
  27. return diff;
  28. }
  29.  
  30. return so1.field2 - so2.field2;
  31. }
  32.  
  33.  
  34. int main()
  35. {
  36. srand(time(NULL));
  37.  
  38. Lista < object > ll;
  39.  
  40. object so;
  41.  
  42. clock_t t1 = clock();
  43.  
  44. for (int i = 0; i < 100000; i++)
  45. {
  46. so.field1 = rand() % 10001;
  47. so.field2 = rand() % 26 + 'A';
  48. ll.push_back(so);
  49. }
  50.  
  51. clock_t t2 = clock();
  52. double time = (t2 - t1) / (double)CLOCKS_PER_SEC;
  53. cout << "Czas dodawania 100000 elementow z przodu: " << time << endl;
  54.  
  55. t1 = clock();
  56.  
  57. for (int i = 0; i < 100000; i++)
  58. {
  59. so.field1 = rand() % 10001;
  60. so.field2 = rand() % 26 + 'A';
  61. ll.push_front(so);
  62. }
  63.  
  64. t2 = clock();
  65. time = (t2 - t1) / (double)CLOCKS_PER_SEC;
  66. cout << "Czas dodawania 100000 elementow z tylu: " << time << endl;
  67.  
  68.  
  69. t1 = clock();
  70.  
  71. for (int i = 0; i < 10000; i++)
  72. {
  73. ll.remove_back();
  74. }
  75.  
  76. t2 = clock();
  77. time = (t2 - t1) / (double)CLOCKS_PER_SEC;
  78. cout << "Czas usuwania 10000 elementow z tylu: " << time << endl;
  79.  
  80. t1 = clock();
  81.  
  82. for (int i = 0; i < 10000; i++)
  83. {
  84. ll.remove_front();
  85. }
  86.  
  87. t2 = clock();
  88. time = (t2 - t1) / (double)CLOCKS_PER_SEC;
  89. cout << "Czas usuwania 10000 elementow z przodu: " << time << endl;
  90.  
  91.  
  92. so.field1 = 23;
  93. so.field2 = 'B';
  94.  
  95. object ao;
  96. ao.field1 = 25;
  97. ao.field2 = 'M';
  98.  
  99.  
  100. ll.print(5);
  101.  
  102. ll.return_by_index(15);
  103.  
  104. ll.replace(10000, so);
  105.  
  106. t1 = clock();
  107.  
  108. ll.search(so,*difference);
  109.  
  110. t2 = clock();
  111. time = (t2 - t1) / (double)CLOCKS_PER_SEC;
  112. cout << "Czas wyszukiwania elementu po wartosci: " << time << endl;
  113.  
  114. ll.print(8);
  115.  
  116. t1 = clock();
  117.  
  118. ll.remove_by_value(so,*difference);
  119.  
  120. t2 = clock();
  121. time = (t2 - t1) / (double)CLOCKS_PER_SEC;
  122. cout << "Czas usuwania elementu po wartosci: " << time << endl;
  123.  
  124. ll.remove_by_value(ao,*difference);
  125.  
  126. ll.print(9);
  127.  
  128. ll.insert(2, ao);
  129.  
  130. ll.print(4);
  131.  
  132. t1 = clock();
  133.  
  134. ll.clear();
  135.  
  136. t2 = clock();
  137. time = (t2 - t1) / (double)CLOCKS_PER_SEC;
  138. cout << "Czas usuwania calej listy: " << time << endl;
  139.  
  140.  
  141.  
  142.  
  143. system("PAUSE");
  144. return 0;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement