Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void func(int count, int init[], int dest[], int buf[]) {
- if (count == 0) return;
- func(count - 1, init, buf, dest);
- int indexi = 0, indexd = 9;
- while (init[indexi] == 0)indexi++;
- while (dest[indexd] != 0)indexd--;
- swap (init[indexi], dest[indexd]);
- func(count - 1, buf, dest, init);
- }
- int main() {
- setlocale(LC_ALL, "RUS");
- int rod1[10];
- for (int i = 0; i < 10; i++) {
- rod1[i] = i + 1;
- }
- int rod2[10]{};
- int rod3[10]{};
- cout << "Исходный стержень" << endl;
- for (int i = 0; i < 10; i++) {
- cout << rod1[i] << " ";
- }
- cout << endl;
- cout << "Конечный стержень" << endl;
- for (int i = 0; i < 10; i++) {
- cout << rod3[i] << " ";
- }
- cout << endl;
- cout << "Буферный стержень" << endl;
- for (int i = 0; i < 10; i++) {
- cout << rod2[i] << " ";
- }
- cout << endl<<endl;
- func(10, rod1, rod3, rod2);
- cout << "Исходный стержень" << endl;
- for (int i = 0; i < 10; i++) {
- cout << rod1[i] << " ";
- }
- cout << endl;
- cout << "Конечный стержень" << endl;
- for (int i = 0; i < 10; i++) {
- cout << rod3[i] << " ";
- }
- cout << endl;
- cout << "Буферный стержень" << endl;
- for (int i = 0; i < 10; i++) {
- cout << rod2[i] << " ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement