首页 > 其他 > 详细

HeapSort自己yy-未完成

时间:2016-12-09 00:28:50      阅读:200      评论:0      收藏:0      [点我收藏+]
#include <iostream>
#include <cstdio>

using namespace std;

const int maxn=1e5+7;

int a[maxn];
int HeapSize;
int n;
//原子操作
//不要总想着搞一个大新闻,一次操作干太多操作
//只要不符合堆的性质我们就交换
void Heapify(){
    int id=1;
    while(id<=HeapSize){
        int lson=2*id;
        int rson=2*id+1;
        int t;
        if(lson>Heapsize&&rson>Heapsize){
            break;
        }
        if(rson>HeapSize){
            t=lson;
        }
        else if(a[lson]<a[rson]){
            t=lson;
        }
        else{
            t=rson;
        }
        if(a[t]<a[id]){
            swap(a[t],a[id]);
        }
        id=t;
    }
}
void MakeHeap(){

}
void HeapSort(){

}

int main(){
    scanf("%d",&n);
    HeapSize=n;
    int i;
    for(i=1;i<=n;++i){
        scanf("%d",&a[i]);
    }
    return 0;
}

 

HeapSort自己yy-未完成

原文:http://www.cnblogs.com/linkzijun/p/6147017.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!