posts - 297,  comments - 15,  trackbacks - 0
//二叉树先序遍历非递归
void InOrderTraverse(BiTree T,SqStack s)
{
 
    InitStack(s);         //初始化栈
 BiTree p = T;
 Push(s,p);        //树根进栈
 while(!StackEmpty(s) || !p)
 {//当栈空或结点为空时结束
  if(p)
  {//P非空访问结点,结点进栈,访问该结点左子树
            printf("%d ",p->data);
            Push(s,p);
   p = p->lchild ;
  }
  else
  {//P空结点出栈,访问右子树
   Pop(s,p);
   p=p->rchild ;
  }
 }
}

int SumYe(BiTree T)
{//求二叉树叶结点数之和
 if(!T) return 0;
 if(!T->lchild && !T->rchild ) return 1;
 return SumYe(T->lchild)+SumYe(T->rchild);
}

int HightTree(BiTree T)
{//求二叉树高
 int hl = 0;//记录左子树高
 int hr = 0;//记录右子树高
 if(!T)  return 0;
 hl = HightTree(T->lchild);
 hr = HightTree(T->rchild);
 return (hl>hr) ? hl+1 : hr+1 ;
}

posted on 2009-03-19 00:09 chatler 阅读(267) 评论(0)  编辑 收藏 引用 所属分类: Algorithm

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(10)

随笔分类(307)

随笔档案(297)

algorithm

Books_Free_Online

C++

database

Linux

Linux shell

linux socket

misce

  • cloudward
  • 感觉这个博客还是不错,虽然做的东西和我不大相关,觉得看看还是有好处的

network

OSS

  • Google Android
  • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
  • os161 file list

overall

搜索

  •  

最新评论

阅读排行榜

评论排行榜