quick sort

Màu nền
Font chữ
Font size
Chiều cao dòng

 

#include <stdio.h>

#include <conio.h>

 void  quicksort(int a[20],int first,int last)

 {

      int key=a[(first+last)/2],temp;

      int i=first;

      int j=last;

    while(i<=j)

    {

       while(a[i]<key)i++;

       while(a[j]>key)j--;

   if(i<=j)

        {

         temp=a[i];

         a[i]=a[j];

         a[j]=temp;

         i++;

         j--;

        }

    }

   quicksort(a,first,j);

   quicksort(a,i,last);

}                    

  void main()

   {

    int i;

    int a[5]={9,2,1,3,5};

    quicksort(a,0,4);

        for(i=0;i<5;i++)

          printf("%2d",a[i]);

    getch();

   }

Bạn đang đọc truyện trên: Truyen2U.Pro