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 }
  • 相关阅读:
    指针和数组的关系
    深入学习数组
    const关键字与指针
    野指针是什么
    指针带来的一些符号的理解
    指针的本质
    内存管理之堆
    内存管理之栈
    元类
    断点调式和面向对象进阶
  • 原文地址:https://www.cnblogs.com/nagishiro/p/13232399.html
Copyright © 2011-2022 走看看