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

    #include "stdafx.h"
    
    void PrintFunc(int a[], int n)
    {
        for (int i = 0; i < n;i++)
        {
            printf("%d ", a[i]);
        }
    
        printf("
    ");
    }
    
    
    //快速排序
    int QSort(int a[], int n)
    {
        int low = 0;
        int high = n - 1;
        int tmp, j;
        
        while (low < high)
        {
            for (j = low; j < high;++j)
            {
                if (a[j+1]<a[j])
                {
                    tmp = a[j];
                    a[j] = a[j +1];
                    a[j + 1] = tmp;
                }
            }
            
            high--;
    
            for (j = high;j>low; --j)
            {
                if (a[j]<a[j-1])
                {
                    tmp = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = tmp;
                }
            }
    
            ++low;
    
            PrintFunc(a, n);
        }
    
        return 0;
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        int a[] = {9,8,7,6,5,4,3,2,1, 0};
        
        //InsertSort(a, 10);
        QSort(a, 10);
        //PrintFunc(a, 10);
        return 0;
    }

    Out:

    E:Debug>AlgoTest.exe
    0 8 7 6 5 4 3 2 1 9
    0 1 7 6 5 4 3 2 8 9
    0 1 2 6 5 4 3 7 8 9
    0 1 2 3 5 4 6 7 8 9
    0 1 2 3 4 5 6 7 8 9

  • 相关阅读:
    ORACLE(系统表emp) 基本与深入学习
    jQuery框架 的四个入口函数
    函数
    sql1999语法
    左连接,右连接
    Oracle单行函数用法
    Kettle
    order by 排序
    sql*plus
    sql基本语句
  • 原文地址:https://www.cnblogs.com/kernel0815/p/4878194.html
Copyright © 2011-2022 走看看