[자료구조] 자료구조와 자바
- 최초 등록일
- 2003.05.09
- 최종 저작일
- 2003.05
- 4페이지/ 한컴오피스
- 가격 1,000원
목차
없음
본문내용
1. 자연수 n을 입력으로 받아, n개의 원소를 가진 집합의 모든 가능한 순열을 출력하는 순환 함수를 Java로 작성하라. 예를 들어, n이 3이라면, 3개의 원소를 가진 집합 {a, b, c}에 대한 모든 순열의 집합 {(a, b, c), (a, c, b), (b, a, c), (b, c, a), (c, a, b), (c, b, a)}를 출력하게 된다. n개의 주어진 원소에 대해 n!개의 순열이 출력되어야 한다.
import java.io.*;
class Circulation
{
static int i=0,c,n,temp;
static int[] list = new int[9];
public static void Fac(int list[], int i, int c)
{
if(i==c)
{
for(int j=0;j<=c;j++)
System.out.print(list[j]);
System.out.print("||");
}
else
{
for(int j=i;j<=c;j++)
{
temp=list[i]; list[i]=list[j]; list[j]=temp;
Fac(list, i+1, c);
temp=list[i]; list[i]=list[j]; list[j]=temp;
}
}
}
참고 자료
없음