Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<typename Type>
- int right(
- const Type* box,
- const size_t size,
- const size_t start,
- const size_t step
- ) {
- return box[(start + step) % size];
- }
- template<typename Type>
- int left(
- const Type* box,
- const size_t size,
- const size_t start,
- size_t step
- ) {
- step %= size;
- return box[(size + start - step) % size];
- }
- int main() {
- int box[] = { 1, 2, 9, 5, 3, 6, 8 };
- const auto size = sizeof(box) / sizeof(box[0]);
- const auto index = 6U;
- const auto step = 10U;
- cout
- << right(box, size, index, step) << '\n'
- << left(box, size, index, step)
- << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement