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;
    }
  • 相关阅读:
    scrapy Request方法
    from lxml import etree报错
    python文件管道 下载图集
    scrapy基本爬虫,采集多页
    python操作excel xlwt (转)
    matplotlib 设置标题 xy标题等
    matplotlib 饼状图
    acwing 600. 仰视奶牛
    LeetCode 684. 冗余连接
    LeetCode 200. 岛屿数量
  • 原文地址:https://www.cnblogs.com/yangyh/p/1739600.html
Copyright © 2011-2022 走看看