/*
PROG: butter
LANG: C++
*/
download c_heap_sort
//In the name of God
#include
#include
#include
using namespace std;
const int P = 800 + 10, N = 500 + 10, inf = P * N * 225;
int h[P], nh = 0, ver[P], ind[P], t[30], hh;
vector
inline void my_swap (int x, int y) {
swap (ver[x], ver[y]);
swap (ind[ ver[x] ], ind[ ver[y] ]);
swap (h[x], h[y]);
}
//x == index
void bobble_up (int x) {
if (x != 1 && h[x] < x ="="" mc =" x;"> h[x*2] && x*2<=nh) mc = x*2; if (h[mc] > h[x*2 + 1] && x*2+1 <= nh) mc = x*2+1; if (mc != x) { my_swap (x, mc); bobble_down (mc); } } //x != index && x == value inline void insert_key (int x) { h[++nh] = x; bobble_up (nh); } inline int extract_min () { int r = h[1]; my_swap(1, nh--); bobble_down(1); return r; } //x == index inline void modifi_key (int x, int val) { h[x] = val; bobble_up (x); bobble_down (x); } int main () { int x; while (cin >> x) {
insert_key (x);
t[hh++] = x;
cerr << x << endl;
}
cerr << "hello\n";
sort (t, t+hh);
/*for (int i=1; i
cerr << h[i] << " ";
cerr << endl;*/
for (int i=0; i
cerr << t[i] << " ";
cerr << endl;
while(nh)
cerr << extract_min () << " ";
cerr << endl;
return 0;
}
copy the code above
The end of the c sample program
for more samples see other posts in the blog
please leave messages and comment below
This comment has been removed by a blog administrator.
ReplyDeletemoncler, moncler outlet, links of london, bottes ugg, moncler, moncler, doudoune canada goose, sac louis vuitton pas cher, juicy couture outlet, canada goose, moncler, pandora charms, pandora charms, replica watches, louis vuitton, pandora jewelry, lancel, canada goose, louis vuitton, ugg boots uk, swarovski, louis vuitton, canada goose uk, wedding dresses, moncler, ugg,uggs,uggs canada, hollister, supra shoes, juicy couture outlet, toms shoes, canada goose outlet, ugg pas cher, montre pas cher, canada goose, moncler, karen millen, swarovski crystal, louis vuitton, pandora jewelry, ugg,ugg australia,ugg italia, marc jacobs, thomas sabo, coach outlet, moncler, canada goose, canada goose outlet
ReplyDeletejimmy choo shoes, converse outlet, north face outlet, insanity workout, soccer jerseys, wedding dresses, nike air max, ralph lauren, mcm handbags, oakley, hollister, lululemon, mont blanc, valentino shoes, vans shoes, vans, abercrombie and fitch, nike huarache, new balance, hollister, bottega veneta, nike trainers, birkin bag, celine handbags, ghd, soccer shoes, asics running shoes, instyler, timberland boots, beats by dre, nfl jerseys, converse, reebok shoes, nike roshe, hollister, ferragamo shoes, p90x workout, gucci, louboutin, north face outlet, iphone cases, babyliss, chi flat iron, baseball bats, longchamp, ray ban, nike air max, herve leger, mac cosmetics
ReplyDelete