close
Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 已解決
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 已解決 
Manage your social media

Best social media tool for image publishing to Facebook and Twitter. Look amazing and delight your followers. Get 40% off when you sign up today.
From our sponsors
c語言 HeapSort 排序
Oct 21st 2013, 11:58

用HeapSort 排序
我發現怎麼第一個數字都沒有辦法排序到
例如 6 0 1 1 1 1 5 6 8 8 ------------> 第一個沒有排序 其他都 ok
眼睛看到快花了
可以幫我看看哪裡漏掉了嗎 ??

謝謝

#include<stdio.h>
#include<math.h>
#define FLOOR(x)((INT)x)

void MaxHeap_Heapify(int a[],int i, int n)
{
int l,r,largest,temp;
l=2*i;
r=l+1;
if(l<=n && a[l]>a[i])
largest=l;
else
largest=i;
if(r<=n && a[r]>a[largest])
largest=r;
if(largest !=i)
{
temp=a[i];
a[i]=a[largest];
a[largest]=temp;
MaxHeap_Heapify(a,largest,n);
}
}

void Build_Max_Heap(int a[],int n)
{
int i,j;
j=FLOOR((n/2));
for(i=j;j>-1;i--)
MaxHeap_Heapify(a,i,n);
}

void Heap_Sort(int a[],int n)
{
int i,temp;
Build_Max_Heap(a,n);
for(i=n;i>=2;i--)
{
temp=a[1];
a[1]=a[i];
a[i]=temp;
n=n-1;
MaxHea[_Heapify(a,1,n);

}
}

void main()
{
srand(time(NULL));
for (i=0;i<10;i++)
{
aa[i]=rand()%10;
}
Heap_Sort(aa,10);
for(i=0;i<10;i++)
{
printf("%d",aa[i]);
}

}

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. Five Filters recommends:

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 nnokikasb 的頭像
    nnokikasb

    奶酪陷阱第3集| 韓劇線上看2016 乳酪陷阱線上看EP03. 本劇簡介=>乳酪陷阱 人物介紹+劇情簡介. 本劇觀後感=>(韓劇)乳酪陷阱 分集劇情+心得

    nnokikasb 發表在 痞客邦 留言(0) 人氣()