Oto i kod wyznaczający wszystkie permutację bez powtórzeń na zbiorze n-element-owym.
Czy potrafił by ktoś zapisać go w pseudokodzie(czyli zrozumiale) z góry dzięki
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <cstdlib>
#define q 30
using namespace std;
void swap(char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
void permute(char *a, int l, int r)
{
string linia;
fstream plik;
int i;
if (l == r)
{
plik.open("plik.txt", ios::out | ios::app);
if(plik.good() == true)
{
cout<<a<<endl;
plik <<a<<endl;
plik.close();
}
}
else
{
for (i = l; i <= r; i++)
{
swap((a+l), (a+i));
permute(a, l+1, r);
swap((a+l), (a+i));
}
}
}
int main()
{
char str[q];
cout<<"Podaj wyraz n elementowy z zakresu 30"<<endl;
cin>>str;
int n = strlen(str);
permute(str, 0, n-1);
return 0;
}