Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <stdio.h>
  5. #include <time.h>
  6. #include <utility>
  7. #include <cstdio>
  8. using namespace std;
  9.  
  10. //int *rosnacy = new int[rozmiar];
  11. int i=0;
  12. int *tabrosnacy;
  13. int *tabprzysty;
  14. struct listajednokierunkowa{
  15. int wartoscciagu;
  16. listajednokierunkowa *next;
  17.  
  18.  
  19. }*zmienna;
  20. struct listajednokierunkowa *head = NULL;
  21. struct listajednokierunkowa *pierwszyel = NULL;
  22. struct listajednokierunkowa *pomocnik = NULL;
  23. struct listajednokierunkowa *ostatniel = NULL;
  24. void wyczyscliste()
  25. {
  26. head=pierwszyel;
  27.  
  28. while(head->next!=NULL)
  29. {
  30.  
  31. pomocnik=head->next;
  32. head=NULL;
  33. head=pomocnik;
  34.  
  35. }
  36. pierwszyel=NULL;
  37. }
  38. void dodawaniedolisty(int rozmiar)
  39. {
  40. listajednokierunkowa *element = new listajednokierunkowa;
  41.  
  42. head=pierwszyel;
  43.  
  44.  
  45. while(head->next!=NULL)
  46. {
  47.  
  48. pomocnik=head->next;
  49. head=pomocnik;
  50.  
  51. }
  52.  
  53. for(int x=0;x<rozmiar;x++)
  54. {
  55. element->next=NULL;
  56. element->wartoscciagu=tabprzysty[x];
  57. head->next=element;
  58. head=element;
  59. head->next=NULL;
  60. ostatniel=head;
  61.  
  62.  
  63.  
  64. /* element->next=NULL;
  65. element->wartoscciagu=tabprzysty[x];
  66. head=element;
  67. head->next=element;
  68. head=head->next;
  69. ostatniel=head;*/
  70. }
  71.  
  72.  
  73. /* for(int x=0;x<rozmiar;x++)
  74. {
  75.  
  76.  
  77. head=ostatniel;
  78.  
  79. element->next=NULL;
  80. element->wartoscciagu=tabprzysty[x];
  81.  
  82. //cout<<"TTT";
  83. i++;
  84. //cout<<element->wartoscciagu;
  85. //cout<<"\n";
  86.  
  87. //head=element;
  88. head->next=element;
  89. head=element;
  90. ostatniel=head;
  91.  
  92. }*/
  93. //cout<<"\n";
  94. //cout<<head->wartoscciagu;
  95. //cout<<"\n";
  96. }
  97. void usuwaniezlisty(int rozmiar)
  98. { int x;
  99. head=pierwszyel;
  100.  
  101. while(head->next!=NULL)
  102. {
  103.  
  104. pomocnik=head->next;
  105. for(int i=0;i<rozmiar; i++)
  106. {
  107. x=tabprzysty[i];
  108.  
  109. if(head->wartoscciagu==x)
  110. {
  111.  
  112.  
  113. head=NULL;
  114.  
  115. }
  116. }
  117.  
  118.  
  119. head=pomocnik;
  120.  
  121.  
  122. }
  123.  
  124. }
  125.  
  126. void stworzliste()
  127. {
  128.  
  129. listajednokierunkowa *element = new listajednokierunkowa;
  130. if(pierwszyel==NULL)
  131. {
  132.  
  133. element->wartoscciagu=tabrosnacy[i];
  134. i++;
  135. //cout<<element->wartoscciagu;
  136. //cout<<"\n";
  137. element->next=NULL;
  138. head=element;
  139. pierwszyel=head;
  140.  
  141. }
  142. /* if(i==1)
  143. {
  144. head=head->next;
  145. head->wartoscciagu=tabrosnacy[i];
  146. head->next=NULL;
  147. pierwszyel->next=head;
  148.  
  149. }*/
  150. else
  151. {
  152.  
  153. element->next=NULL;
  154. element->wartoscciagu=tabrosnacy[i];
  155. //cout<<"TTT";
  156. i++;
  157. //cout<<element->wartoscciagu;
  158. //cout<<"\n";
  159.  
  160. //head=element;
  161. head->next=element;
  162. head=element;
  163. ostatniel=head;
  164.  
  165.  
  166. }
  167.  
  168.  
  169. }
  170. void rosnace(int rozmiar)
  171. {
  172. tabrosnacy = new int[rozmiar];
  173. int j = 1;
  174. for (int i = 0; i < rozmiar; i++)
  175. {
  176. tabrosnacy[i] = j;
  177. j += 2;
  178. }
  179. //cout << endl << "CIAG ROSNACY" << endl;
  180. //for (int k = 0; k < rozmiar; k++)
  181. //cout << tab[k] << " | ";
  182.  
  183. }
  184. void parzyste(int rozmiar)
  185. {
  186. tabprzysty = new int[rozmiar];
  187.  
  188. for (int i = 0; i < rozmiar; i++)
  189. {
  190.  
  191. int j=rand();
  192. while(j%2!=0)
  193. {
  194. j=rand();
  195. }
  196. tabprzysty[i] = j;
  197. }
  198. //cout << endl << "CIAG ROSNACY" << endl;
  199. //for (int k = 0; k < rozmiar; k++)
  200. //cout << tab[k] << " | ";
  201.  
  202. }
  203. int main()
  204. {
  205. clock_t t;
  206. int rozmiarrosn=100000;
  207.  
  208.  
  209. for(int x1=0; x1<20; x1++)
  210. {
  211. rosnace(rozmiarrosn);
  212. parzyste(rozmiarrosn);
  213. t = clock();
  214. for(int x=0;x<rozmiarrosn;x++)
  215. {
  216. stworzliste();
  217. }
  218. t = clock() - t;
  219. printf("%fs STWORZENIE LISTY\n",((float)t)/CLOCKS_PER_SEC);
  220. t = clock();
  221.  
  222. usuwaniezlisty(rozmiarrosn/100);
  223.  
  224. t = clock() - t;
  225. printf("%fs USUNIECIE ELEMENTOW Z LISTY\n",((float)t)/CLOCKS_PER_SEC);
  226. t = clock();
  227.  
  228. dodawaniedolisty(rozmiarrosn/100);
  229. t = clock() - t;
  230. printf("%fs DODAWANIE DO LISTY\n",((float)t)/CLOCKS_PER_SEC);
  231. wyczyscliste();
  232. i=0;
  233. rozmiarrosn=rozmiarrosn+10000;
  234. }
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241. return 0;
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement