快排的递归与非递归实现

import java.util.*;
//快排的实现
public class quikSort{
	
   //(1)递归实现快速排序
   public static void quickSort(int[]s,int l,int r){
	 
	 if(lpivot) //从右向左
         	j--;
           if(j>i)
           {
            s[i++]=s[j];    
           }
          while(i stack = new LinkedList();  //用栈模拟
        if(start < end) {
            stack.push(end);
            stack.push(start);
            while(!stack.isEmpty()) {
                int l = stack.pop();
                int r = stack.pop();
                int index = partition(a, l, r);
                if(l < index - 1) {
                    stack.push(index-1);
                    stack.push(l);
                }
                if(r > index + 1) {
                    stack.push(r);
                    stack.push(index+1);
                }
            }
        }
    }
    
  public static int partition(int[] a, int start, int end) {
        int pivot = a[start];
        while(start < end) {
            while(start < end && a[end] >= pivot)
                end--;
            a[start] = a[end];
            while(start < end && a[start] <= pivot)
                start++;
            a[end] = a[start];
        }
        a[start] = pivot;
        return start;
    }
   //打印数组的值
   public static void PrintArray(int[]arr)
   {
   	  for(int i=0;i

快排的递归与非递归实现_第1张图片

快排的递归与非递归实现_第2张图片

舞动的排序算法
http://v.youku.com/v_show/id_XMzMyODk4NTQ4.html

你可能感兴趣的:(常见面试题)