Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added day10 cpp codes * Readme and code modified
- Loading branch information
1 parent
f7fadeb
commit c430e13
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* @author : YashMeh | ||
* @date : 28/1/2019 | ||
*/ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
//Using STL | ||
void permute(string s) | ||
{ | ||
sort(s.begin(),s.end()); | ||
do | ||
{ | ||
cout<<s<<endl; | ||
} while (next_permutation(s.begin(),s.end())); | ||
} | ||
//Using recursion | ||
void permute(string smallPart,int n,string firstChar) | ||
{ | ||
if(n==1) | ||
{ | ||
cout<<firstChar+smallPart<<endl; | ||
return; | ||
} | ||
for(int i=0;i<n;i++) | ||
{ | ||
permute(smallPart.substr(1),n-1,firstChar+smallPart[0]); | ||
rotate(smallPart.begin(),smallPart.begin()+1,smallPart.end()); | ||
} | ||
} | ||
main() | ||
{ | ||
string s="1234"; | ||
string r=""; | ||
permute("1234"); | ||
permute(s,s.size(),r); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters