码迷,mamicode.com
首页 > 其他好文 > 详细

HeapSort自己yy-未完成

时间:2016-12-09 00:31:51      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:using   ios   color   style   for   sort   新闻   自己   main   

#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-未完成

标签:using   ios   color   style   for   sort   新闻   自己   main   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!