2013年2月27日

堆排序

摘要: #include<stdio.h>int n,k,len;void HeapAdjust(int a[],int s,int m){ int j; int e=a[s]; for(j=2*s;j<=m;j*=2) { if(j<m&&a[j]<a[j])++j; if(e>=a[j])break; a[s]=a[j]; s=j; } a[s]=e;}void HeapSort(int a[]){ int i,e; for(i=len/2;i>0;i--) HeapAd... 阅读全文

posted @ 2013-02-27 16:34 dokc 阅读(159) 评论(0) 推荐(0) 编辑

快速排序

摘要: int a[1000];void qs(int low,int high){ int l=low,h=high,e=a[l]; while(l<h) { while(l<h&&a[h]>=e) h--; if(l<h) a[l++]=a[h]; while(l<h&&a[l]<=e) l++; if(l<h) a[h--]=a[l]; } a[l]=e; if(l-1>low) qs(low,l-1); if(h+1<high) qs(h+1,high);} 阅读全文

posted @ 2013-02-27 16:30 dokc 阅读(120) 评论(0) 推荐(0) 编辑

导航