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

    void QuickSort(SeqList R,int low,int high)

        
    // 对R[low..high]快速排序
        int pivotPos;    // 划分后的基准记录的位置
        if(low < high)
        
    {
            
    // 仅当区间长度大于1时才须排序
            pivotPos = Partition(R,low,high); // 对R[low..high]做划分
            QuickSort(R,low,pivotPos - 1); // 对左区间递归排序
            QuickSort(R,pivotPos + 1,high); // 对右区间递归排序
        }

    }
     // QuickSort

    void QuickSort(int[] x, int s, int t)
    {
        
    int temp;
        
    int i = s, j = t;
        
    if(s < t)
        
    {
            temp 
    = x[s];
            
    do
            
    {
                
    while(j > i && x[j] >= temp)
                
    {
                    j
    --;
                }

                
    if(i < j)
                
    {
                    x[i] 
    = x[j];
                    i
    ++;

                }

                
    while(i < j && x[i] <= temp)
                
    {
                    i
    ++;
                }

                
    if(i < j)
                
    {
                    x[j] 
    = x[i];
                    j
    --;
                }

            }
    while(i < j);
            x[i] 
    = temp;
            QuickSort(x,s,j
    -1);
            QuickSort(x,j
    +1,t);

        }

    }
  • 相关阅读:
    Boost线程库学习笔记
    sizeof运算符
    用法char ch=getchar()正确性详解
    C语言中的缓冲输出
    算术运算的溢出行为 and 一个数内存中表示1的个数
    ARP、RARP、ICMP、ping
    http和https协议
    关于宋词频率统计(R语言)
    Backbone.js API中文文档
    腾讯小Q书桌图标怎么实现的啊?
  • 原文地址:https://www.cnblogs.com/xiaodi/p/296482.html
Copyright © 2011-2022 走看看