목차
1.Selction Sort.
(1)Source
(2)Capture
2.Insert Sort.
(1)Source
(2)Capture
3.Merge Sort.
(1)Source
(2)Capture
4.Quick Sort.
(1)Source
(2)Capture
(1)Source
(2)Capture
2.Insert Sort.
(1)Source
(2)Capture
3.Merge Sort.
(1)Source
(2)Capture
4.Quick Sort.
(1)Source
(2)Capture
본문내용
= partition(data, first, n);
//파티션. 피봇 왼쪽 값은 피봇보다 작은값 피봇 오른쪽 값은 피봇보다 큰값
for(int m=0;m<10;++m)//중간과정 for문
System.out.print(data[m]+BLANKS); //중간과정 보여줌
System.out.println();
n1 = pivotIndex - first;
n2 = n- n1- 1;
quicksort(data,first,n1); //pivot 왼쪽 sorting
quicksort(data,pivotIndex+1,n2); //pivot 오른쪽 sorting
}
}
public static int partition(int[] data, int first, int n){
int pivot = data[first]; //첫번째 값을 pivot 값으로
int tooBigIndex = first + 1; //pivot 다음 index에서 시작
int tooSmallIndex = first + n - 1;//맨 오른쪽 index에서 시작
int temp;
while(tooBigIndex <= tooSmallIndex)
{
if((tooBigIndex + 1) == data.length) //원소의 개수가 작다면
break;
while(data[tooBigIndex] <= pivot) //pivot 보다 큰 원소를 찾음
{
if((tooBigIndex + 1) == data.length)
break;
tooBigIndex++;
}
while(data[tooSmallIndex] > pivot)
//pivot 보다 작은 원소를 찾음
tooSmallIndex--;
if(tooBigIndex < tooSmallIndex) //index가 교차 되지 않았을때
{
//pivot보다 큰값은 오른쪽으로 작은값은 왼쪽으로
temp = data[tooBigIndex];
data[tooBigIndex] = data[tooSmallIndex];
data[tooSmallIndex] = temp;
}
}
data[first] = data[tooSmallIndex];
//data[first]값과 index 교차되었을때
data[tooSmallIndex] = pivot;//tooSmallIndex값과 교환
return tooSmallIndex;//리턴
}
public static void main(String[] args){
final String BLANKS = " ";//빈칸
int i;
int[] data = new int[10];
Random random = new Random(); //Random 변수 선언
for(i=0; i<10; i++)
data[i] = random.nextInt(100); //random 수를 100으로 한정
System.out.println("Here is the original array :");
for(i=0; i
System.out.print(data[i] + BLANKS);
//보기 편하기 위해 print 메소드, 정렬전
System.out.printf("\n\n");
quicksort(data,0,data.length);//quick Sort 호출
System.out.println("\nIn sorted order(Quick Sort), the numbers are : ");
for(i=0; i
System.out.print(data[i] + BLANKS);//정렬후
System.out.println();
}
}
4-(2)Capture Result
//파티션. 피봇 왼쪽 값은 피봇보다 작은값 피봇 오른쪽 값은 피봇보다 큰값
for(int m=0;m<10;++m)//중간과정 for문
System.out.print(data[m]+BLANKS); //중간과정 보여줌
System.out.println();
n1 = pivotIndex - first;
n2 = n- n1- 1;
quicksort(data,first,n1); //pivot 왼쪽 sorting
quicksort(data,pivotIndex+1,n2); //pivot 오른쪽 sorting
}
}
public static int partition(int[] data, int first, int n){
int pivot = data[first]; //첫번째 값을 pivot 값으로
int tooBigIndex = first + 1; //pivot 다음 index에서 시작
int tooSmallIndex = first + n - 1;//맨 오른쪽 index에서 시작
int temp;
while(tooBigIndex <= tooSmallIndex)
{
if((tooBigIndex + 1) == data.length) //원소의 개수가 작다면
break;
while(data[tooBigIndex] <= pivot) //pivot 보다 큰 원소를 찾음
{
if((tooBigIndex + 1) == data.length)
break;
tooBigIndex++;
}
while(data[tooSmallIndex] > pivot)
//pivot 보다 작은 원소를 찾음
tooSmallIndex--;
if(tooBigIndex < tooSmallIndex) //index가 교차 되지 않았을때
{
//pivot보다 큰값은 오른쪽으로 작은값은 왼쪽으로
temp = data[tooBigIndex];
data[tooBigIndex] = data[tooSmallIndex];
data[tooSmallIndex] = temp;
}
}
data[first] = data[tooSmallIndex];
//data[first]값과 index 교차되었을때
data[tooSmallIndex] = pivot;//tooSmallIndex값과 교환
return tooSmallIndex;//리턴
}
public static void main(String[] args){
final String BLANKS = " ";//빈칸
int i;
int[] data = new int[10];
Random random = new Random(); //Random 변수 선언
for(i=0; i<10; i++)
data[i] = random.nextInt(100); //random 수를 100으로 한정
System.out.println("Here is the original array :");
for(i=0; i
//보기 편하기 위해 print 메소드, 정렬전
System.out.printf("\n\n");
quicksort(data,0,data.length);//quick Sort 호출
System.out.println("\nIn sorted order(Quick Sort), the numbers are : ");
for(i=0; i
System.out.println();
}
}
4-(2)Capture Result
소개글