1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <stdlib.h> typedef struct ; struct { int val,mark; node *lchild,*rchild; }; #define MAXN 100
node* createNodeWithVal(int val) { node *rt = (node*)malloc(sizeof(node)); rt->lchild = rt->rchild = NULL; rt->val = val; rt->mark = 0; return rt; }
node* createTree() { node *rt = createNodeWithVal(4); rt->lchild = createNodeWithVal(2); rt->rchild = createNodeWithVal(6); rt->lchild->lchild = createNodeWithVal(1); rt->lchild->rchild = createNodeWithVal(3); rt->rchild->lchild = createNodeWithVal(5); rt->rchild->rchild = createNodeWithVal(7); return rt; }
int flag = 0; void Judge(node *rt) { if(rt == NULL) return; Judge(rt->lchild); Judge(rt->rchild); if((rt->lchild == NULL && rt->rchild != NULL) || (rt->lchild != NULL && rt->rchild == NULL)) { flag = 1; return; } }
int main() { node *root = createTree(); Judge(root); printf("%dn",flag); return 0; }
|
近期评论