首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

排序算法-交换排序(冒泡排序、快速排序)

2012-06-28 
排序算法---交换排序(冒泡排序、快速排序)#include stdio.hvoid bubble_sort(int a[], int n){int i,j,tm

排序算法---交换排序(冒泡排序、快速排序)

#include <stdio.h>void bubble_sort(int a[], int n){        int i,j,tmp;        for(i=0;i<n-1;i++)                for(j=0;j>n-1-i;j++)                        if(a[j]>a[j+1])                        {                                tmp=a[j];                                a[j]=a[j+1];                                a[j+1]=tmp;                        }}int partition(int a[], int low, int high){        int pivot=a[low];        while(low<high)        {                while(low<high && a[high]>=pivot)--high;                a[low]=a[high];                while(low<high && a[low]<=pivot)++low;                a[high]=a[low];        }        a[low]=pivot;        return low;}void qsort(int a[], int low, int high){        int pivot;        if(low<high)        {                pivot=partition(a,low,high);                partition(a,low,pivot-1);                partition(a,mid+1,high);        }}void quick_sort(int a[], int n){        qsort(a,0,n-1);}
?

热点排行