Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PermutationRecursion.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- void calculate (string str, int left, int right)
- {
- if(left == right)
- {
- cout << str << endl;
- }
- else
- {
- for (int i = left; i <= right; i++)
- {
- swap(str[left], str[i]);
- string swapped = str;
- calculate(swapped, left + 1, right);
- }
- }
- }
- int main()
- {
- string str = "ABC";
- int sizeOfString = str.size();
- calculate(str, 0, sizeOfString-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement