标题:大哥帮帮忙!!!!
取消只看楼主
闯闯
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-6-28
 问题点数:0 回复次数:0 
大哥帮帮忙!!!!

#include<stdio.h>;

#include<stdlib.h>;

#define null 0

#define len sizeof(struct tree)

struct tree

{

int data;

struct tree *left,*right;

};

struct tree *head;

struct tree *creat()

{

struct tree *p,*q,*h,*i;

int n=0,x;

scanf("%d",&x);

while (x!=0)

{

n++;

if (n==1) {

h=(struct tree*)malloc(len);

h->data=x;

h->left=null;

h->right=null;

};

if (n!=1)

{

p=(struct tree*)malloc(len);

p->data=x;

p->left=null;

p->right=null;

q=h;

if (x>q->data) i=q->right;

else i=q->left;

while (i!=null)

{

q=i;

if (x>q->data) i=q->right;

else i=q->left;

};

if (x>q->data) q->right=p;

else q->left=p;

};

scanf("%d",&x);

};

return h;

}

void print(struct tree *p)

{

if (p!=null) {

print(p->left);

printf("%d ",p->data);

print(p->right);

}

}

int depth(nodetype *root) {

      if(root==NULL)

       return 0;

      else {

       h1=depth(root->lch);

       h2=depth(root->rch);

      

  return max(h1,h2)+1;

      }

}

int count(nodetype *root) {

      if(root==NULL)

       return 0;

      else {

       if(root->lch==NULL&&root->rch==NULL)

return 1;

else{

h1=count(root->lch);

        h2=count(root->rch);

        return h1+h2;

       }

}

}

main()

{ int active=10,active2=10,n;

while(active!=0){

printf("1、二叉树操作\n");

printf("2、树操作\n");

printf("0、退出\n");

printf("请选择菜单项:");

scanf("%d",&active);

switch(active){

case 1:

printf("1、建立二叉树\n");

printf("2、叶子结点数\n");

printf("3、二叉树的深度\n");

printf("0、返回\n");

printf("请选择菜单项:");

scanf("%d",&active2);

switch(active2){

case 1:

head=creat();

print(head);

break;

case 2:

printf("%d",count(head));break;

case 3:

printf("%d",depth(head));break;

case 0: break;

}

break;

case 2:

printf("1、建立树\n");

printf("2、结点数\n");

printf("0、返回\n");

printf("请选择菜单项:");

scanf("%d",&active2);

switch(active2){

case 1: sortShuoxue(L);break;

case 2: sortChengxu(L);break;

case 0: break;

}

break;

}

}

}

能不能把这个改成C++语言???? 急用,希望各路高手来帮帮小弟!

搜索更多相关主题的帖子: include null 大哥 
2005-06-28 13:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-21730-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.187262 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved