排序二叉樹的特征是: 某個節點的左子樹的所有節點值都不大于本節點值。 某個節點的右子樹的所有節點值都不小于本節點值。 為了能形象地觀察二叉樹的建立過程,小明寫了一段程序來顯示出二叉樹的結構來。
#include <stdio.h>#include <string.h>#define N 1000#define HEIGHT 100#define WIDTH 1000struct BiTree{ int v; struct BiTree* l; struct BiTree* r;};int max(int a, int b){ return a>b? a : b;}struct BiTree* init(struct BiTree* p, int v){ p->l = NULL; p->r = NULL; p->v = v; return p;}void add(struct BiTree* me, struct BiTree* the){ if(the->v < me->v){ if(me->l==NULL) me->l = the; else add(me->l, the); } else{ if(me->r==NULL) me->r = the; else add(me->r, the); }}//獲得子樹的顯示高度 int getHeight(struct BiTree* me){ int h = 2; int hl = me->l==NULL? 0 : getHeight(me->l); int hr = me->r==NULL? 0 : getHeight(me->r); return h + max(hl,hr);}//獲得子樹的顯示寬度 int getWidth(struct BiTree* me){ char buf[100]; s對于上邊的測試數據,應該顯示出: | /--------------500---/ | |/--200---/ /--509/| | | |100 /--250---/ 507 600/ | | | 220 /--450 650 | 440(如有對齊問題,請參考【圖1.png】)
請分析程序邏輯,填寫劃線部分缺失的代碼。
注意,只填寫缺少的部分,不要填寫已有的代碼或符號,也不要加任何說明文字。
這個全看命.答案是printInBuf(me->r,buf,p2+strlen(sv),y+2)
不過可以從
看出些許來.我就是這么看的. 反正可以慢慢試. 至于具體試多久.我大概試了10分鐘.
新聞熱點
疑難解答