fork download
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. const int N = 10000;
  10. const int T = 100;
  11.  
  12. srand((unsigned)time(0));
  13.  
  14. bool myArray[N] ;
  15. bool temp = true;
  16. int save1 = 0;
  17. int save2 = 0;
  18.  
  19. //initializing myArray
  20. for (int index = 0; index < N/2; index++) {
  21. myArray[index] = false;
  22. }
  23. for (int index = N/2; index < N; index++) {
  24. myArray[index] = true;
  25. }
  26.  
  27. for (int index = 0; index < T; index++) {
  28.  
  29. for (int index1 = 0; index1 < N; index1++) {
  30. save1 = int( N*rand()/RAND_MAX );
  31. save2 = int( N*rand()/RAND_MAX );
  32.  
  33. if ( save1 != 0 || save2 != 0 )
  34. std::cout << "Non zero index: " << save1 << ' ' << save2 << '\n';
  35.  
  36. temp = myArray[save1];
  37. myArray[save1] = myArray[save2] ;
  38. myArray[save2] = temp;
  39. }
  40. }
  41.  
  42. cout<<" Press any key to exit...";
  43. cin.get();
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 16064KB
stdin
e

stdout
 Press any key to exit...