Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

몸짱프로젝트/DisplayPumutation

From ZeroWiki

PsuedoCode

C++ version

  • 개발자 : 나휘동
  • Recursive Function Call 사용
#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;
}

몸짱프로젝트