zoukankan      html  css  js  c++  java
  • 快速排序

    (java版)
    public class Qsort {

    static int Partition(int l[],int low,int high){

    int prvotkey = l[low];
    while(low<high){
    while(low<high && l[high] >= prvotkey)
    high--;
    l[low] = l[high];
    while(low<high && l[low] <= prvotkey)
    low++;
    l[high] = l[low];
    }
    l[low] = prvotkey;
    return low;
    }

    static void QSort(int l[],int low, int high){
    int prvotkey;
    if(low < high){
    prvotkey = Partition(l,low,high);
    QSort(l,low,prvotkey-1);
    QSort(l,prvotkey+1,high);
    }
    else{
    // System.out.println("error!");
    }
    }

    static void quicksort(int l[],int n){
    QSort(l,0,n-1);
    }

    public static void main(String[] args) {
    int a[] = {0,2,5,43,32,65,43,21,87,1};
    int b;
    for(b=0; b<10;b++){
    System.out.print(a[b]+ " ");
    }
    System.out.println();
    quicksort(a,10);
    int c;
    for(c = 0; c<10 ; c++){
    System.out.print(a[c]+" ");
    }
    }

    }

  • 相关阅读:
    windows平台下一款强大的免费代理获取工具
    彻底搞懂Git Rebase
    line-height
    text-indent
    text-decoration
    text-align
    color
    CSS属性汇总
    font
    font-style
  • 原文地址:https://www.cnblogs.com/tangtang-123/p/4436034.html
Copyright © 2011-2022 走看看