EvilStream~One Year~

失败了…对大家说声sorry…也好也好…然后呢?一起走吧…与你…

  • 日历

    12月 2008
    « Sep    
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  
  • about:myself


    所有华而不实的软件风格,特效表示无语..例如Vista,但是对于大型游戏也许越华丽越吸引人吧.
    反对缺德公司的作品,如腾迅QQ,vagaa等,反非主流,反脑残滥用.
    生活中我是个比较令人无语的gg,兴趣爱好广泛,编程,反病毒,魔方,音乐(Rap和古典(只懂一点),周杰伦通吃^_^)
    联系方式:
    Javran.C[At]gmail.com(EMail And GTalk)(防止垃圾邮件,把[At]改成该改的东西)
    Javran(百度HI,为了防广告设了验证,随便打点什么,一般我 都不会拒绝的)^_^
  • Action!

QuickSort(快速排序)Source(C++/C)

Posted by Javran on 01月 2nd, 2008

感谢Felix提供的C++源代码!

#include <stdio.h>
#include <stdlib.h>
#define N 1010

void sort(int *a,int start,int end);

int main()
{
int s[N],n;
while(scanf(”%d”,&n)!=EOF)
{
for(int i=0;i<n;i++)scanf(”%d”,&s[i]);
sort(s,0,n-1);
for(int i=0;i<n;i++)printf(”%d “,s[i]);
printf(”\n”);
}
return 0;
}

void sort(int *a,int start,int end)
{
int i=start,j=end,temp;
if(start<end)
{
temp=a[start];
while(i!=j)
{
while(i<j && a[j]>temp)j–;
if(i<j)a[i]=a[j],i++;
while(i<j && a[i]<temp)i++;
if(i<j)a[j]=a[i],j–;
}
a[i]=temp;
sort(a,start,i-1);
sort(a,i+1,end);
}
}

4 Responses to “QuickSort(快速排序)Source(C++/C)”

  1. lenloon Says:

    真不错,用linux系统?

  2. javran Says:

    我用Linux?怎么回事?

  3. Felix021 Says:

    1L的评论真是神奇。。。

    话说现在我都不写qsort函数了,都用STL的sort(), 随机化的qsort,保证了不会有最坏情况的n*n出现。

  4. Javran Says:

    我也都用随机的了,毕竟基本不可能退化啊

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WP Hashcash