PsuedoCode


C++ version

  • 개발자 : 나휘동
  • Recursive Function Call 사용

~cpp 
#include <iostream.h>

void perm(char * list, int i , const int n);
void swap(char & aVal1, char & aVal2);
const int SIZE = 4;
char arr[SIZE] = {'a', 'b', 'c', 'd'};
void main()
{
	perm(arr, 0, SIZE-1);
}

void perm(char * list, int i , const int n)
{
	int j;
	if ( i == n ){
		for ( j = 0 ; j <= n ; j++ )
			cout << list[j];
		cout << "\t";
	}
	else{
		for ( j = i ; j <= n ; j++ ){
			swap(list[i], list[j]);
			perm(list, i+1, n);
			swap(list[i], list[j]);
		}
	}
}

void swap(char & aVal1, char & aVal2)
{
	char temp = aVal1;
	aVal1 = aVal2;
	aVal2 = temp;
}

Retrieved from http://wiki.zeropage.org/wiki.php/몸짱프로젝트/DisplayPumutation
last modified 2021-02-07 05:29:29