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

    代码
    //============================================================================
    // Name        : Sort.cpp
    // Author      : 
    // Version     :
    // Copyright   : Your copyright notice
    // Description : Hello World in C++, Ansi-style
    //============================================================================

    #include 
    <iostream>
    using namespace std;
    template
    <class T>
    int partition(T data[],int low,int high)
    {
        
    int t=data[low];
        
    while(low<high)
        {
            
    while(low<high&&t<=data[high])
                high
    --;
            
    if(low<high)
                data[low
    ++]=data[high];
            
    while(low<high&&t>=data[low])
                low
    ++;
            
    if(low<high)
                data[high
    --]=data[low];


        }
        data[low]
    =t;
        
    return low;

    }
    template
    <class T>
    void quickSort(T data[],int i,int j)
    {
        
    int d;
        
    if(i<j)
        {
            d
    =partition(data,i,j);
            quickSort(data,i,d
    -1);
            quickSort(data,d
    +1,j);
        }
    }
    int main() {
        cout 
    << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
        int t[]={12,34,6,-4,6,46,78,42,65,8,43};

        quickSort(t,
    0,11);
        
    for(int i=0;i<10;i++)
            printf(
    "%d ",t[i]);
        
    return 0;
    }
  • 相关阅读:
    flash使用lua
    如何写出兼容大部分浏览器的CSS 代码
    typeof 详解
    人月神话阅读笔记(三)
    人月神话阅读笔记(二)
    仓库物资管理
    动手动脑(四)
    人月神话阅读笔记(一)
    动手动脑(六 文件操作)及课后作业
    java异常处理
  • 原文地址:https://www.cnblogs.com/yangyh/p/1739600.html
Copyright © 2011-2022 走看看