Recursive and non-recursive implementation of fast rows _ fast Row

Source: Internet
Author: User
Import java.util.*; 
	 	 Fast-ranked implementation public class quiksort{//(1) Recursive implementation fast sort public static void QuickSort (Int[]s,int l,int R) {if (l<r) {
	     int i=l;
	     int j=r; int pivot=s[l];
           Take the first number of each child array as the base while (I&LT;J) {while (I<j&&s[j]>pivot)/Right-to-left j--;    
           if (j>i) {s[i++]=s[j];
           while (I<j&&s[i]<pivot)//From left to right i++; 
           if (i<j) {s[j--]=s[i];
         }} S[i]=pivot;
         QuickSort (s,l,i-1);   
         
	 QuickSort (S,I+1,R); }///non-recursive fast sort public static void Nonrecquicksort (int[] a,int Start,int end) {linkedlist<integer>  stack = new linkedlist<integer> ();
            Using the stack to simulate 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[st
        Art];
            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; }//print array value public static void PrintArray (Int[]arr) {for (int i=0;i<arr.length;i++) {Syste
   	  M.out.print (arr[i]+ "");

   } System.out.println (); public static void Main (string[)args) {int[]arr={3,6,5,2,5,4,3,8};
       PrintArray (arr);
       QuickSort (arr,0,arr.length-1);
       Nonrecquicksort (arr,0,arr.length-1);
   PrintArray (arr);
 }
 }


A sort of dance algorithm
Http://v.youku.com/v_show/id_XMzMyODk4NTQ4.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.