📄 二叉树的创建与遍历-经典教程-岛主电子站.htm
字号:
] [双击滚屏] 查看权限: 普通文章</TD></TR>
<TR>
<TD
style="FONT-WEIGHT: bold; FONT-SIZE: 15px; COLOR: #cc0000; HEIGHT: 50px"
align=middle><FONT color=#ff0000>二叉树的创建与遍历</FONT></TD></TR>
<TR>
<TD class=soncontent>
<TABLE
style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all; TEXT-ALIGN: left"
width="100%" border=0>
<TBODY>
<TR>
<TD
style="COLOR: #ffffff; BACKGROUND-COLOR: #b7b7b7; TEXT-ALIGN: center">作者:秦皇岛岛主 来源:岛主电子站 阅读次数: 79 发表日期: 2006-9-9
16:41:54</TD></TR>
<TR>
<TD id=zoom vAlign=top>
<P>
<IMG onmousewheel="return cgimg(this);"
src="二叉树的创建与遍历-经典教程-岛主电子站.files/sktree1.gif"
onload=javascript:ContentImage(this);></P>
<P>运行时输入ABD空格E空格空格F空格G空格空格CH空格空格空格回车,可以先根创建二叉树如图。屏幕显示 ABDEFGCH(先根遍历)</P>
<P>
DEBFGAHC(中根遍历)</P>
<P>
EDGHBHCA(后根遍历)</P>
<P> </P>
<P>#define NULL 0<BR>#include <stdio.h><BR>struct
tree{<BR> char info;<BR> struct tree
*lchild;<BR> struct tree *rchild;<BR>};<BR>struct tree
*creat(){<BR> struct tree *temp;<BR> char
ch;<BR> ch=getchar();<BR> if(ch=='\n')
exit(0);<BR> else if(ch==32)
temp=NULL;<BR> else{<BR> temp=(struct tree
*)malloc(sizeof(struct
tree));<BR> temp->info=ch;<BR> temp->lchild=creat();<BR> temp->rchild=creat();<BR> }<BR> return
temp;<BR>}</P>
<P>void preorder(struct tree
*root){<BR> if(root==NULL)<BR> return;<BR> else{<BR> printf("%c",root->info);<BR> if(root->lchild!=NULL)<BR> preorder(root->lchild);<BR> if(root->rchild!=NULL)<BR> preorder(root->rchild);<BR> }<BR>}</P>
<P>void inorder(struct tree
*root){<BR> if(root==NULL)<BR> return;<BR> else{<BR> if(root->lchild!=NULL)<BR> inorder(root->lchild);<BR> printf("%c",root->info);<BR> if(root->rchild!=NULL)<BR> inorder(root->rchild);<BR> }<BR>}</P>
<P>void postorder(struct tree
*root){<BR> if(root==NULL)<BR> return;<BR> else{<BR> if(root->lchild!=NULL)<BR> postorder(root->lchild);<BR> if(root->rchild!=NULL)<BR> postorder(root->rchild);<BR> printf("%c",root->info);<BR> }<BR>}<BR>main(){<BR> struct
tree
*M;<BR> M=creat(M);<BR> preorder(M);<BR> printf("\n");<BR> inorder(M);<BR> printf("\n");<BR> postorder(M);<BR> printf("\n");<BR>}</P></TD></TR>
<TR>
<TD height=10></TD></TR>
<TR>
<TD class=disable_font align=right>[录入:岛主电子站 责编:秦皇岛岛主]
</TD></TR></TBODY></TABLE><!--上一页、下一页-->
<TR>
<TD style="BACKGROUND-COLOR: #e4e4e4">上一篇:<A
href="http://www.dzdzz.com/showart.asp?id=11">数字温度传感器DS18B20介绍</A><BR>下一篇:<A
href="http://www.dzdzz.com/showart.asp?id=9">常用ASCII
码对照表</A></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center>
<TBODY>
<TR>
<TD height=8></TD></TR></TBODY></TABLE><!--公共评论-->
<TABLE class=right_table cellSpacing=0 cellPadding=2 align=center>
<TBODY>
<TR>
<TD class=left_title> <IMG height=12
src="二叉树的创建与遍历-经典教程-岛主电子站.files/left_title_arrow.gif"
width=10> 【公共评论】[目前共有<SPAN class=key_font>0</SPAN>条评论]<SPAN
id=menutitle1 style="CURSOR: hand" onclick=showsubmenu(1)>
[发表评论]</SPAN></TD></TR>
<TR class=tablebody>
<TD><SPAN class=disable_font>暂时还没有评论</SPAN></TD></TR>
<TR class=tablebody>
<TD align=right>第0页,共0页,共<SPAN
class=key_font>0</SPAN>条评论 </TD></TR></TBODY></TABLE>
<DIV id=submenu1 style="DISPLAY: none">
<TABLE class=sontable cellSpacing=0 cellPadding=0 align=center>
<TBODY>
<TR>
<TD height=8></TD></TR></TBODY></TABLE><!--发表评论-->
<TABLE class=right_table cellSpacing=0 cellPadding=0 align=center>
<FORM name=addremark action="" method=post>
<TBODY>
<TR class=tablebody>
<TD class=left_title style="FONT-WEIGHT: normal"
colSpan=2> <IMG height=12
src="二叉树的创建与遍历-经典教程-岛主电子站.files/left_title_arrow.gif"
width=10> 【发表评论】<SPAN class=disable_font> [ 最多字数:<INPUT
class=disable_font
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px"
disabled maxLength=4 size=3 value=150
name=total> 已用字数:<INPUT class=disable_font
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px"
disabled maxLength=4 size=3 value=0 name=used>剩余字数:<INPUT
class=disable_font
style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px"
disabled maxLength=4 size=3 value=150 name=remain>]</SPAN></TD></TR>
<TR class=tablebody>
<TD align=middle width="15%" height=13>您的称呼</TD>
<TD width="85%" height=13><INPUT maxLength=10 name=remarker><INPUT
type=hidden maxLength=50 value=61.150.43.47 name=remarker_ip></TD></TR>
<TR class=tablebody>
<TD vAlign=top align=middle>您的评论</TD>
<TD><TEXTAREA onkeydown=gbcount(this.form.remark,this.form.total,this.form.used,this.form.remain); onkeyup=gbcount(this.form.remark,this.form.total,this.form.used,this.form.remain); title=不能超过150个汉字 name=remark rows=6 cols=60></TEXTAREA></TD></TR>
<TR class=tablebody>
<TD colSpan=2> 验 证 码 <INPUT maxLength=4
size=4 name=GetCode> <IMG
src="二叉树的创建与遍历-经典教程-岛主电子站.files/Ft_Getcode.bmp"></TD></TR>
<TR class=tablebody>
<TD align=middle colSpan=2><INPUT class=put onmouseover="this.className='overput'" onclick="{if(confirm('您确定要提交此条评论吗?\n\n注意:切忌不要胡乱提交评论,否则后果自负!')){return true;}return false;}" onmouseout="this.className='put'" type=submit value=发表 name=submit> <INPUT class=put onmouseover="this.className='overput'" onmouseout="this.className='put'" type=reset value=重写 name=reset><INPUT
type=hidden value=10 name=art_id><INPUT type=hidden value=true
name=addremark></TD></TR>
<TR>
<TD background="" colSpan=2
height=28></TD></TR></FORM></TBODY></TABLE></DIV><!--相关新闻-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
<TBODY>
<TR>
<TD height=8></TD></TR></TBODY></TABLE>
<TABLE class=right_table cellSpacing=0 cellPadding=0 align=center>
<TBODY>
<TR>
<TD class=left_title id=menutitle2 style="CURSOR: hand"
onclick=showsubmenu(2)> <IMG height=12
src="二叉树的创建与遍历-经典教程-岛主电子站.files/left_title_arrow.gif"
width=10> <SPAN class=fontshadow>【相关新闻】</SPAN></TD></TR>
<TR>
<TD class=soncontent id=submenu2 style="DISPLAY: none"><SPAN
class=disable_font> <SPAN
class=disable_font>没有相关新闻</SPAN></SPAN></TD></TR></TBODY></TABLE>
<TABLE class=sontable cellSpacing=0 cellPadding=0 align=center>
<TBODY>
<TR>
<TD height=8></TD></TR></TBODY></TABLE>
<TABLE class=right_table cellSpacing=0 cellPadding=0 align=center>
<TBODY>
<TR>
<TD class=left_title id=menutitle3 style="CURSOR: hand"
onclick=showsubmenu(3)> <IMG height=12
src="二叉树的创建与遍历-经典教程-岛主电子站.files/left_title_arrow.gif"
width=10> <SPAN class=fontshadow>【相关文章】</SPAN></TD></TR>
<TR>
<TD class=soncontent id=submenu3 style="DISPLAY: none"><SPAN
class=disable_font><SPAN
class=disable_font>没有相关文章</SPAN></SPAN></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
<TBODY>
<TR>
<TD height=8></TD></TR></TBODY></TABLE><!--相关软件-->
<TABLE class=right_table cellSpacing=0 cellPadding=0 align=center>
<TBODY>
<TR>
<TD class=left_title id=menutitle4 style="CURSOR: hand"
onclick=showsubmenu(4)> <IMG height=12
src="二叉树的创建与遍历-经典教程-岛主电子站.files/left_title_arrow.gif"
width=10> <SPAN class=fontshadow>【相关软件】</SPAN></TD></TR>
<TR>
<TD class=soncontent id=submenu4 style="DISPLAY: none"><SPAN
class=disable_font> <SPAN
class=disable_font>没有相关软件</SPAN></SPAN></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
<TBODY>
<TR>
<TD height=8></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><!--页面主体结束--><!--脚部导航及脚部信息-->
<TABLE class=maintable cellSpacing=0 cellPadding=0 align=center>
<TBODY>
<TR>
<TD class=diary></TD></TR>
<TR>
<TD bgColor=#dddddd height=2></TD></TR></TBODY></TABLE>
<TABLE class=topfoottable cellSpacing=0 cellPadding=0 align=center>
<TBODY>
<TR>
<TD colSpan=2 height=8></TD></TR>
<TR>
<TD align=middle width=220><IMG alt=创意无限,真诚永远
src="二叉树的创建与遍历-经典教程-岛主电子站.files/footerlogo.gif" border=0></TD>
<TD
style="FONT-WEIGHT: bold; LINE-HEIGHT: 150%; FONT-FAMILY: Arial,宋体"><SPAN
class=fontshadow>| <A title=友情链接 href="http://www.dzdzz.com/link.asp"
target=_self>友情链接</A> | <A title=在线留言
href="http://www.dzdzz.com/guestbook.asp"
target=_self>在线留言</A> | <A title=本站版权声明
href="http://www.dzdzz.com/channel.asp?id=1"
target=_self>版权声明</A> | <A title=关于我们
href="http://www.dzdzz.com/channel.asp?id=2"
target=_self>关于我们</A> | <A title=网站管理
href="http://www.dzdzz.com/admin/admin_login.asp"
target=_blank>网站管理</A> | <A title=欢迎注册成为会员
href="http://www.dzdzz.com/user.asp" target=_self><FONT
color=#ff0000>会员注册</FONT></A> | <A title=全站搜索及互联网搜索
href="http://www.dzdzz.com/search.asp" target=_self>超级搜索</A> | <A
href="http://www.dzdzz.com/viewstate.asp">网站帮助</A></SPAN><BR><SPAN
style="FONT-WEIGHT: normal; FONT-FAMILY: Arial,宋体">Copyright© 2005-2010
岛主电子站, All rights reserved。<BR>站长:秦皇岛岛主 建站时间:2005-8-25</SPAN> <A
href="http://www.miibeian.gov.cn/" target=_blank><SPAN
class=disable_font>[蜀ICP备06019232]</SPAN></A>
<SCRIPT language=JavaScript>
document.write("<a a target='_blank' href=/stat/Infolist.asp onFocus='if(this.blur)this.blur()' >");
document.write("<img src='/stat/count.asp?Referer=&Width="+escape(screen.width)+"&Height="+escape(screen.height)+"' border='0' width='16' height='16' align='absmiddle'>");
document.write("</a>");
</SCRIPT>
</TD></TR>
<TR>
<TD colSpan=2 height=8></TD></TR></TBODY></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -