如题

解决方案 »

  1.   

    C语言:快速排序
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define N 10int QSorting(int *result ,int first,int end)
    {
         int key = result[first];
         while(first < end)
         {
              while(first < end&&result[end] >= key)
              end--;
              if(first != end)
                    result[first++] = result[end];
              while(first < end && result[first] <= key)
                   first++;
              if(first != end)
                   result[end--] = result[first];
          }
          result[first] = key;
          return first;
    }
    void Qsort(int *result,int first,int end)
    {
         if(first < end )
         {
                 int middle = QSorting(result,first,end);
                 Qsort(result,first,middle-1);
                 Qsort(result,middle+1,end);
         }
    }int main()
    {
         int value[N] = {18,94,61,87,34,31,78,56,14,17};
         int i = 0;
         int sum = 0;
         Qsort(value,0,N-1);
         for(i = 0 ;i < N;i++)
         {
              sum = sum + value[i];
              printf("%d\n",value[i]);
          }
          printf("the result:%d\n",value[N/2]-sum/N);
          return 0;
      

  2.   

    快速排序
    Sub QuickSort(List() As Double)
        Dim i As Double, j As Double, b As Double
        Dim l As Double, t As Double, r As Double, d As Double    Dim p(1 To 100) As Double
        Dim w(1 To 100) As Double    k = 1
        p(k) = LBound(List)
        w(k) = UBound(List)
        l = 1
        d = 1
        r = UBound(List)
        Do
    toploop:
            If r - l < 9 Then GoTo bubsort
            i = l
            j = r
            While j > i
               comp = comp + 1
               If List(i) > List(j) Then
                   swic = swic + 1
                   t = List(j)
                   oldx1 = List(j)
                   oldy1 = j
                   List(j) = List(i)
                   oldx2 = List(i)
                   oldy2 = i
                   newx1 = List(j)
                   newy1 = j
                   List(i) = t
                   newx2 = List(i)
                   newy2 = i
                   d = -d
               End If
               If d = -1 Then
                   j = j - 1
                    Else
                        i = i + 1
               End If
           Wend
               j = j + 1
               k = k + 1
                If i - l < r - j Then
                    p(k) = j
                    w(k) = r
                    r = i
                    Else
                        p(k) = l
                        w(k) = i
                        l = j
                End If
                d = -d
                GoTo toploop
    bubsort:
        If r - l > 0 Then
            For i = l To r
                b = i
                For j = b + 1 To r
                    comp = comp + 1
                    If List(j) <= List(b) Then b = j
                Next j
                If i <> b Then
                    swic = swic + 1
                    t = List(b)
                    oldx1 = List(b)
                    oldy1 = b
                    List(b) = List(i)
                    oldx2 = List(i)
                    oldy2 = i
                    newx1 = List(b)
                    newy1 = b
                    List(i) = t
                    newx2 = List(i)
                    newy2 = i
                End If
            Next i
        End If
        l = p(k)
        r = w(k)
        k = k - 1
        Loop Until k = 0
    End Sub
      

  3.   

    VB算法之二分法查找算法
    http://bbs.leafhome.com/dispbbs.asp?boardID=2&ID=40&page=1
      

  4.   

    楼上的将代码贴出来吧!一目了然!呵呵http://bbs.leafhome.com/dispbbs.asp?boardID=2&ID=40&page=1我这打不开呢,多谢仁兄
      

  5.   

    zq972(旅游归来,好累……) ( ) 信誉:100    Blog 
    Arry1(0) = 67
    Arry1(1) = 68
    Arry1(2) = 43
    Arry1(3) = 89
    Arry1(4) = 16
    Call QuickSort(Arry1)
    For i = LBound(Arry1) To UBound(Arry1)
       Debug.Print Arry1(i)
    Next
    得到的结果:
     67 
     0 
     16 
     43 
     68 
     89
      

  6.   

    快速排序
    http://bbs.leafhome.com/dispbbs.asp?boardID=2&ID=41&page=1'快速排序算法(递归算法)
    Public Sub QuickSort(ByRef aStrSort() As String, ByVal lngleft As Long, ByVal lngright As Long)
        Dim i As Long
        Dim j As Long
        Dim temp As String
        i = lngleft
        j = lngright
        temp = aStrSort(i)
        
    NextStep:
        Do Until i >= j
            While (aStrSort(j) > temp And j > i)
                j = j - 1
            Wend
            If j > i Then
                aStrSort(i) = aStrSort(j)
                aStrSort(j) = temp
                i = i + 1
            End If
            While (aStrSort(i) < temp And j > i)
                i = i + 1
            Wend
            If j > i Then
                aStrSort(j) = aStrSort(i)
                aStrSort(i) = temp
                j = j - 1
            End If
        Loop
        If lngleft < i - 1 Then QuickSort aStrSort, lngleft, i - 1
        If lngright > i + 1 Then QuickSort aStrSort, i + 1, lngright
    End Sub 
      

  7.   

    VB算法之二分法查找算法
    http://bbs.leafhome.com/dispbbs.asp?boardID=2&ID=40&page=1'二分法查找算法(查找失败返回-1,数组下标从0开始)Public Function BinSearch(ByRef strElement() As String, ByVal strKey As String) As Long
        Dim lngLow As Long
        Dim lngHigh As Long
        Dim lngMiddle As Long
        lngLow = 0
        lngHigh = UBound(strElement)
        While (lngLow <= lngHigh)
            lngMiddle = (lngLow + lngHigh) / 2
            If strElement(lngMiddle) = strKey Then
                BinSearch = lngMiddle
                Exit Function
            Else
                If strElement(lngMiddle) > strKey Then
                    lngHigh = lngMiddle - 1
                Else
                    lngLow = lngMiddle + 1
                End If
            End If
        Wend
        BinSearch = -1  '查找失败
    End Function
      

  8.   

    谢谢楼上的xyz2004(逍遥者),继续顶
      

  9.   

    zq972(最近不想写代码,好累~~~~) 的快排是可以用的(经测试),但上标为1。我讨厌Bubble类型,把它们全部换成Long型也能用。