main.cpp 646 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "List.h"
  2. #include <iostream>
  3. #include <time.h>
  4. using namespace std;
  5. void iosif(int count, int step)
  6. {
  7. clock_t start = clock();
  8. List<int> l;
  9. for(int i = 0; i < count; i++) {
  10. l.add(i);
  11. }
  12. int i = 0;
  13. while(l.lenght > 1) {
  14. l.pop(i);
  15. i += step - 1;
  16. i %= l.lenght;
  17. }
  18. clock_t end = clock();
  19. double sec = (double)(end - start) / CLOCKS_PER_SEC;
  20. cout << "time: " << sec << " answer: " << l[0] << endl;
  21. }
  22. int main() {
  23. iosif(1000, 3);
  24. iosif(5000, 3);
  25. iosif(10000, 3);
  26. iosif(50000, 3);
  27. iosif(100000, 3);
  28. iosif(500000, 3);
  29. iosif(1000000, 3);
  30. }