请高手完善一下本程序。。。。。。。。。。。。。tree
c++吧
全部回复
仅看楼主
level 6
tonyfirst1 楼主
// btree.cpp : Defines the entry point for the console application.//#include "stdafx.h"struct Btree {int self;Btree *parent;Btree *left;Btree *right;Btree *child[2];};void digui(Btree *tree);bool FindLeftRightLeaf(Btree *NewBlock);static int j = 0;int main(int argc, char* argv[]){Btree ttrr;ttrr.self = 100;digui(&ttrr);//FindLeftRightLeaf(&ttrr);scanf("%d");return 0;}void digui(Btree *tree){int i = 1; while (true) {j++;if (j > 3){break;}for (int i = 0;i < 2;i++){tree->child[i] = new Btree; tree->child[i]->self = j; tree->child[i]->parent = tree; digui(tree->child[i]);} }return;}bool FindLeftRightLeaf(Btree *NewBLOCK){if (NewBLOCK == NULL){return true;}for (int i = 0;i < 2;i++){if (NewBLOCK->child[i] != NULL){if (i == 0) {NewBLOCK->child[i]->right = NewBLOCK->child[i + 1];if (NewBLOCK->left != NULL){NewBLOCK->child[i]->left =NewBLOCK->left->child[1];}else{NewBLOCK->child[i]->left = NULL;}}else if (i == 2){NewBLOCK->child[i]->left = NewBLOCK->child[i - 1];if (NewBLOCK->right != NULL){NewBLOCK->child[i]->right =NewBLOCK->right->child[0];}else{NewBLOCK->child[i]->right = NULL;}}else{NewBLOCK->child[i]->left = NewBLOCK->child[i - 1];NewBLOCK->child[i]->right = NewBLOCK->child[i + 1];}}FindLeftRightLeaf(NewBLOCK->child[i]);}return false;}
2007年08月22日 14点08分 1
1