zoukankan      html  css  js  c++  java
  • 快速排序(简单)

    源代码:

    #include <iostream>
      void QuickSort(int arr[], int start, int end);
      void swap(int& a, int& b);
      
      int main()
      {
          int a[] = { 7,12,5,8,4,2,10,15 };
          int size = sizeof(a) / sizeof(int);
          QuickSort(a,0,size-1);     for (int i = 0; i < size; i++)
         {
             std::cout << a[i] << ", ";
         }
         std::cout << std::endl;
     }
     
     void swap(int& a, int& b) 
     {
         int tmp = a;
         a = b;
         b = tmp;
     }
     
     void QuickSort(int arr[],int start,int end) 
     {
         if (start > end)
             return;
         int k = arr[start];
         int i = start, j = end;
         while (i < j) {
             while (j > i && arr[j] > k)
                 --j;
             swap(arr[i],arr[j]);
             while (i < j && arr[i] < k)
                 ++i;
             swap(arr[i], arr[j]);
         }
         QuickSort(arr,start,i-1);
         QuickSort(arr, i + 1, end);
     }
  • 相关阅读:
    mybatis的延时加载缓存机制
    mybatis03
    事务
    codeforces-200B
    codeforces-339B
    codeforces-492B
    codeforces-266B
    codeforces-110A
    codeforces-887B
    codeforces-69A
  • 原文地址:https://www.cnblogs.com/duanqibo/p/15729633.html
Copyright © 2011-2022 走看看