// 可设2013.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <limits.h> struct node{ char t; int value; struct node *right,*left; }; struct node *A[100]; int len,heapsize; struct node *newnode() { struct node *p = (node*)malloc(sizeof(node)); p->value = 0 ; p->left = p->right = NULL; return p; }; int RIGHT(int i ) { return i*2+1; } int LEFT(int i) { return i*2; } int PARENT(int i) { return i/2; } void MIN_HEAPIFY(int i ) { int l = LEFT(i); int r = RIGHT(i); int lest; if(l <= heapsize && A[l]->value < A[i]->value) lest = l ; else lest = i; if(r <= heapsize && A[r]->value < A[lest]->value ) lest = r; if(i != lest) { struct node *temp; temp = A[i]; A[i] = A[lest]; A[lest] = temp; MIN_HEAPIFY(lest); } } void BUILD_MAX_HEAP() { heapsize = len; for(int i = len/2 ;i >= 1; i --) MIN_HEAPIFY(i); } void HEAP_EXTRACT_MIN() { struct node *max ; max = A[1]; A[1] = A[heapsize]; A[heapsize] = max; heapsize = heapsize -1; MIN_HEAPIFY(1); } void HEAP_CHANGE_KEY(int i) { while(i > 1 && A[PARENT(i)]->value > A[i]->value) { struct node *temp = A[i]; A[i] = A[PARENT(i)]; A[PARENT(i)] = temp; i = PARENT(i); } } char ans[100] = {0}; void dotree(int i,struct node *p) { if(p->left != NULL) { ans[i] = '0'; dotree(i+1,p->left); ans[i] = '