The Gateway to Computer Science Excellence
0 votes
59 views
Write a $C$ program to fins all permutations of a string (having at most 6 characters). For example, a string of $3$ characters like $"abc"$ has 6 possible permutations: $”abc", "acb", "bca", "bac", "cab", "cba".$
in Programming by Boss (41.7k points) | 59 views

1 Answer

0 votes
we can solve it using backtracking

string s;

int permutation(int i , int n){

if(i==n-1)

cout<<s;

else{

for(int j=i;j<n;j++){

swap(s[j], s[i]);

permutation(i+1 , n);

swap(s[j] ,s[i]);

}

}

}
by (103 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,666 questions
56,131 answers
193,669 comments
93,303 users