zoukankan      html  css  js  c++  java
  • [数据结构] 快速排序+折半搜索

     1 数据结构的练习与巩固
     2 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     3 //折半搜索
     4 int Quick_Search(int List[], int Length, int Number)
     5 {
     6     int Low, High, Middle;
     7     Low = 0;
     8     High = Length-1;
     9     
    10     while (High >= Low)
    11     {
    12         Middle = (Low + High) / 2;
    13         if (List[Middle] == Number)
    14             return Middle;
    15         if (List[Middle] < Number)
    16             Low = Middle + 1;
    17         if (List[Middle] > Number)
    18             High = Middle - 1;
    19     }
    20     return -1;
    21 }
    22 
    23 //快速排序
    24 void Quick_Sort(int List[], int Low, int High)
    25 {
    26     int i, j;
    27     i = Low;
    28     j = High;
    29     int Key = List[Low];
    30 
    31     if(Low < High)
    32     {
    33         while (j > i)
    34         {
    35             while (List[j] >= Key && j > i)
    36                 j--;
    37             if (j > i)
    38                 List[i++] = List[j];
    39 
    40             while (List[i] < Key && j > i)
    41                 i++;
    42             if (j > i)
    43                 List[j--] = List[i];
    44         }
    45         List[i] = Key;
    46 
    47         Quick_Sort(List, Low, i - 1);
    48         Quick_Sort(List, i + 1, High);
    49     } 
    50 }
  • 相关阅读:
    [POJ 1417] True Liars
    [POJ 2912] Rochambeau
    [NOIP 2010] 关押罪犯
    [BZOJ 3365] Distance Statistics
    【BZOJ 2821】作诗
    【IOI 2011】Race
    【POJ 2828】Buy Tickets
    FATFS 文件系统
    w25q128 优化读写函数
    keil5编译时出现 MDK-Pro middleware is not allowed with this license
  • 原文地址:https://www.cnblogs.com/nagishiro/p/13232399.html
Copyright © 2011-2022 走看看