Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions permutation-string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// C++ program to print all
// permutations with duplicates allowed
#include <bits/stdc++.h>
using namespace std;


// Function to print permutations of string
// This function takes three parameters:
// 1. String
// 2. Starting index of the string
// 3. Ending index of the string.
void permute(string a, int l, int r)
{
// Base case
if (l == r)
cout<<a<<endl;
else
{
// Permutations made
for (int i = l; i <= r; i++)
{

// Swapping done
swap(a[l], a[i]);

// Recursion called
permute(a, l+1, r);

//backtrack
swap(a[l], a[i]);
}
}
}

// Driver Code
int main()
{
string str = "ABC";
int n = str.size();
permute(str, 0, n-1);
return 0;
}

// This is code is contributed by rathbhupendra