More actions
imported>Unknown No edit summary |
(Repair batch-0005 pages from live compare) |
||
| Line 9: | Line 9: | ||
void swap(char & aVal1, char & aVal2); | void swap(char & aVal1, char & aVal2); | ||
const int SIZE = 4; | const int SIZE = 4; | ||
char arr | char arr[SIZE] = {'a', 'b', 'c', 'd'}; | ||
void main() | void main() | ||
{ | { | ||
| Line 20: | Line 20: | ||
if ( i == n ){ | if ( i == n ){ | ||
for ( j = 0 ; j <= n ; j++ ) | for ( j = 0 ; j <= n ; j++ ) | ||
cout << list | cout << list[j]; | ||
cout << "\t"; | cout << "\t"; | ||
} | } | ||
else{ | else{ | ||
for ( j = i ; j <= n ; j++ ){ | for ( j = i ; j <= n ; j++ ){ | ||
swap(list | swap(list[i], list[j]); | ||
perm(list, i+1, n); | perm(list, i+1, n); | ||
swap(list | swap(list[i], list[j]); | ||
} | } | ||
} | } | ||
| Line 40: | Line 40: | ||
---- | ---- | ||
[[몸짱프로젝트]] | [[몸짱프로젝트]] | ||
Latest revision as of 00:44, 27 March 2026
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;
}