Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define A (1 << 15)
- typedef int B;
- typedef int C;
- typedef struct D {
- C E;
- B F;
- int G;
- } D;
- D H[A], *I, *J[A];
- int R;
- void init_heap() {
- I = H - 1;
- R = 0;
- }
- void S(D* K) {
- int G = K->G, L, M, N;
- D *O, *Q, *P;
- C E = K->E;
- while (G) {
- O = J[L = (G - 1) >> 1];
- if (O->E >= E) break;
- J[G] = O;
- O->G = G;
- G = L;
- }
- while ((M = (G << 1) | 1) < R) {
- Q = J[M];
- if ((N = M + 1) < R && (P = J[N])->E > Q->E) {
- Q = P;
- M = N;
- }
- if (Q->E <= E) break;
- J[G] = Q;
- Q->G = G;
- G = M;
- }
- J[G] = K;
- K->G = G;
- }
- D* heap_push(B F, C E) {
- D* K = ++I;
- K->F = F;
- K->E = E;
- K->G = R++;
- S(K);
- return K;
- }
- B heap_pop() {
- D* T = *J;
- if (--R) {
- D* K = J[R];
- K->G = 0;
- S(K);
- }
- return T->F;
- }
- /* A = heap_size
- * B = t_val
- * C = t_key
- * D = heap_node
- * E = key
- * F = val
- * G = index
- * H = v_heap_nodes
- * I = last_heap_node
- * J = heap
- * K = node
- * L = parent_index
- * M = child_index
- * N = second_child_index
- * O = parent
- * P = second_child
- * Q = child
- * R = heap_size
- * S = heap_update_node
- * T = first */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement