빠른 Java 소스 정렬(반복 및 비반복)

2007 단어
package com.side.quicksort;

import com.side.tests.Stack;// 

public class QuickSort {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		QuickSort t=new QuickSort();
		t.test();
	}
	public void test(){
		//int a[]={10,1,4,7,8,6,3,4,4,4,4,4,2,5,9,4,2};
		int a[]={};
		printArray(a);
		//quickSort(a,0,a.length-1);
		//nonRecrutSort(a);
		nonRecrutQuickSort(a);
		printArray(a);
		//partition(a, 0, 5);
	}
	public void quickSort(int[] a,int start,int end){// 
		if(start startStack=new Stack();// 
		Stack endStack=new Stack();// 
		int start=0;
		int end=a.length-1;
			
		int pivotPos;
		
		startStack.push(start);
		endStack.push(end);
		
		while(!startStack.isEmpty()){
			start=startStack.pop();
			end=endStack.pop();
			pivotPos=partition(a, start, end);
			if(startpivotPos+1){
				startStack.push(pivotPos+1);
				endStack.push(end);
			}
		}
	}

	public void nonRecrutQuickSort(int a[]){
		if(a==null||a.length<=0)return;
		Stack index=new Stack();
		int start=0;
		int end=a.length-1;
		
		int pivotPos;
			
		index.push(start);
		index.push(end);
			
		while(!index.isEmpty()){
			end=index.pop();
			start=index.pop();
			
			pivotPos=partition(a,start,end);
			if(startpivotPos+1){
				index.push(pivotPos+1);
				index.push(end);
			}
		}	
	}
	
	public int partition(int[] a,int start,int end){// , a , start end 
		int pivot=a[start];                     // pivot( pivot=a[start] pivot 
		while(start=pivot) end--;
			a[start]=a[end];
			while(start

좋은 웹페이지 즐겨찾기