#include <string>
#include <iostream>
#include <fstream>
usingnamespace std;
void string_permutation( string &, string&, ofstream & );
int main(){
string orig="abc";
string perm;//empty string
ofstream outFile( "permutation.txt" );//Write in file
string_permutation( orig , perm , outFile );
cout << "Complete!" << endl;
system( "pause" );//Pause window
return 0;
}
//Permutation recursive function
void string_permutation( string& orig, string& perm ,ofstream &outFile){
//If empty string will display the permutation
if( orig.empty() ){
cout << perm << endl;
outFile << perm << endl;
return;
}
for( int i = 0 ; i < orig.size() ; ++i ){
string orig2 = orig;
//erase the alphabet
orig2.erase(i,1);
//Use another variable to call the recursive function
string perm2 = perm;
//Get back position for original
perm2 += orig.at(i);
string_permutation( orig2 , perm2 , outFile );//Recursive function
}
}
and here is my pseudocode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Algorithm( Words , Permutation ){
if ( words is empty ){
write permutation
}
for i <- 0 to words size
TemporaryWords = Words
TemporaryWords.erase( i , 1 )
TemporaryPermutation = Permutation
TemporaryPermutation += Words.at( i )
Algorithm( TemporaryWords , TemporaryPermutation )
end for
i not really familiar with this but i will try my best to do it myself as many as possible before i post and ask any senior tyr to correct me?
my program are done already
i complete with my own.
the problem is i not really expert to write in pseudo code although i know how to do in coding. that's the problem. haha
pseudo code is like writing the english translation of what the program does. Take this as an example:
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
using std::endl;
int main()
{
std::cout << "Hello, pseudo!" << endl;
int x = 5;
for(int i = 0; i < 10; ++i)
{
x += x*i;
}
}
using iostream
let endl be std::endl
function main nothing -> integer:
do
write "Hello, pseudo" and endl to the standard output stream
let x be an integer initialized to 5
for i in [0, 10):
do
add the product of x and i to x
end
end
I don't know of any strict rules on pseudo code, just make it pretty obvious that it is more english than code.
And I also recommend some books which give pseudo code for the actual code.. for example "introduction to algorithms by Thomas H. Cormen). You may not need to buy this book.. you can get some pseudo code snippets from the book online like at google books etc..