빠른 정렬 알고리즘(직접 쓰기)
4797 단어 빠른 정렬
。
package endual;
public class QuickSortClass {
/**
public void recQuickSort(int left, int right) {
if(right-left <= 0) {
return ;
}else {
int partition = partitionIn(left,right) ; // key
recQuickSort(left,partition-1); //
recQuickSort(partition+1,right) ; //
}
}
1.
2. ( )
3. { )
key 。
key , key
( key )
partitionInt()
1. , pivot
2. 。 ,
3. , ,
。 , ,
, 。 , ,
。 , 。
public void recQuickSort(int left, int right) {
if(right-left <= 0) {
return ;
}else {
long provit = theArray[right] ;
int partition = partitionIn(left,right,pivot) ; // key
recQuickSort(left,partition-1); //
recQuickSort(partition+1,right) ; //
}
}
, partitionIntde 。 ,
。 。
**/
}
구분 알고리즘 - 빠른 정렬 알고리즘의 핵심
빠른 정렬
, , 。
, , 。
:
。 : 15 15 15 。
, 。
:
, , 60 60 , 60 ( ,
)。 , ( , , )。
, , , :
45,43,54,21,43,【60】,78,98,78,65,67
, 。 。
, , 。 , 。
。
, 。( , C++ 。
,leftPtr, , ,rightPtr, 。
N
구분 알고리즘의 코드
package endual;
//
public class Partition {
private long[] theArray ;
private int nElems ;
public Partition(long[] theArray, int nElems) {
super();
this.theArray = theArray;
this.nElems = nElems;
}
public void dispay() {
System.out.println(" ") ;
for (long a : this.theArray) {
System.out.println(a);
}
}// end dispay
public int partitionIt(int left, int right, long pivot) {
int leftPtr = left - 1 ;
int rightPtr = right - 1 ;
while (true) {
while (leftPtr < right && theArray[++leftPtr] < pivot) {
}
while (rightPtr < left && theArray[--rightPtr] > pivot) {
}
if (leftPtr >= rightPtr) {
break ;
}else {
swap(leftPtr, rightPtr) ;
}
} //end while
return leftPtr ; // key
}
private void swap(int leftPtr, int rightPtr) {
long temp ;
temp = this.theArray[leftPtr] ;
this.theArray[leftPtr] = this.theArray[rightPtr] ;
this.theArray[rightPtr] = temp ;
}
}
빠른 정렬 알고리즘 이론
빠른 정렬 알고리즘
。 , , 。 NlogN.
, , 。 1962 。
, 。 ,
。
, 。 key 。
。 。
,
코드
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JAVA 버전 정렬 알고리즘의 빠른 정렬 예본고는 JAVA의 빠른 정렬 실현 방법을 실례로 다루고 있다.다음과 같이 여러분에게 참고할 수 있도록 공유합니다. 본고에서 기술한 것이 여러분의 자바 프로그램 설계에 도움이 되기를 바랍니다....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.