Last active
October 2, 2018 08:50
-
-
Save drewxa/781a1c52e0aa6e8776d2a2889a7a9b79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// forward | |
const int N = 1000; | |
int* array = new int[N]; | |
for (int i = 0; i < N; ++i) { | |
array[i] = i + 1; | |
} | |
// время замеряем отсюда | |
int count = 0; | |
int next_index = 0; | |
while (count < N) { | |
++count; | |
next_index = array[next_index]; | |
} | |
// до сюда | |
std::cout << next_index << std::endl; | |
// backward | |
const int N = 1000; | |
int* array = new int[N]; | |
for (int i = 0; i < N; ++i) { | |
array[i] = i - 1; | |
} | |
// время замеряем отсюда | |
int count = 0; | |
int next_index = N - 1; | |
while (count < N) { | |
++count; | |
next_index = array[next_index]; | |
} | |
// до сюда | |
std::cout << next_index << std::endl; | |
// random | |
const int N = 1000; | |
int* array = new int[N]; | |
for (int i = 0; i < N; ++i) { | |
array[i] = // тут погеморней, но можно применить std::shuffle | |
} | |
// время замеряем отсюда | |
int count = 0; | |
int next_index = 0; | |
while (count < N) { | |
++count; | |
next_index = array[next_index]; | |
} | |
// до сюда | |
std::cout << next_index << std::endl; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment