二叉树实验

转载 2007年09月23日 01:30:00

 

<iframe style="WIDTH: 89.81%; HEIGHT: 64px" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4577827332549849&amp;dt=1192819750500&amp;lmt=1192819750&amp;prev_fmts=468x60_as&amp;format=468x15_0ads_al_s&amp;output=html&amp;correlator=1192819750437&amp;channel=1741427766&amp;pv_ch=1741427766%2B&amp;url=http%3A%2F%2Fyzkzoo.5d6d.com%2Fthread-68-1-1.html&amp;color_bg=FFFFFF&amp;color_text=000000&amp;color_link=0000FF&amp;color_url=008000&amp;color_border=336699&amp;ref=http%3A%2F%2Fyzkzoo.5d6d.com%2Fforum-16-1.html&amp;cc=100&amp;ga_vid=1025434795.1192631677&amp;ga_sid=1192817968&amp;ga_hid=1871659779&amp;ga_fc=true&amp;flash=8&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_his=2&amp;u_java=true"></iframe>

<iframe style="WIDTH: 44.33%; HEIGHT: 259px" src="http://pagead2.googlesyndication.com/cpa/ads?client=ca-pub-4577827332549849&amp;cpa_choice=CAEaCB94-nvUZWENUB9QugJQtwRQTVAgULcCUB4&amp;oe=gb2312&amp;dt=1192720966468&amp;lmt=1192720966&amp;format=250x250_as&amp;output=html&amp;correlator=1192720966453&amp;channel=2735220158&amp;url=http%3A%2F%2Fyzkzoo.5d6d.com%2Fthread-67-1-1.html&amp;color_bg=FFFFFF&amp;color_text=000000&amp;color_link=0000FF&amp;color_url=008000&amp;color_border=336699&amp;ad_type=text_image&amp;region=_google_cpa_region_&amp;ref=http%3A%2F%2Fyzkzoo.5d6d.com%2Fforum-16-1.html&amp;cc=100&amp;ga_vid=1025434795.1192631677&amp;ga_sid=1192720940&amp;ga_hid=1155529757&amp;ga_fc=true&amp;flash=8&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_his=2&amp;u_java=true"></iframe>一、二叉树的链式存储结构表示

typedef struct BiTNode{

TElemType data;

struct BitNode *lchild,*rchild;

}BiTNode,*BiTree;

二、二叉树的链式存储算法实现

CreateBiTree(&T,definition);

InsertChild(T,p,LR,c);

三、二叉树的递归法遍历

PreOrderTraverse(T,Visit());

InOrderTraverse(T,Visit());

PostOrderTraverse(T,Visit());

 

示例源程序

#include <alloc.h>

#define ERROR 0;
#define OK 1;


typedef int ElemType;

typedef struct BinaryTree

{
  ElemType data;
  struct BinaryTree *l;
  struct BinaryTree *r;
}*BiTree,BiNode;

BiNode * new()
{
  return( (BiNode *)malloc(sizeof(BiNode)) );
}

CreateSubTree(BiTree *T,ElemType *all,int i)
{
  if ((all==0)||i>16)
    {
      *T=NULL;
      return OK;
    }
  *T=new();
  if(*T==NULL) return ERROR;
  (*T)->data=all;
  CreateSubTree(&((*T)->l),all,2*i);
  CreateSubTree(&((*T)->r),all,2*i+1);
}

CreateBiTree(BiTree *T)
{
  ElemType all[16]={0,1,2,3,0,0,4,5,0,0,0,0,6,0,0,0,};
  CreateSubTree(T,all,1);
}

printelem(ElemType d)
{
  printf("%d/n",d);
}

PreOrderTraverse(BiTree T,int (*Visit)(ElemType d))
{
  if(T){
    if(Visit(T->data))
      if(PreOrderTraverse(T->l,Visit))
        if(PreOrderTraverse(T->r,Visit)) return OK;
    return ERROR;
  } else  return OK;
}
main()
{
  BiTree root;
  CreateBiTree(&root);
  PreOrderTraverse(root,printelem);

}

<iframe style="WIDTH: 52.39%; HEIGHT: 263px" src="http://pagead2.googlesyndication.com/cpa/ads?client=ca-pub-4577827332549849&amp;cpa_choice=CAEaCKcC4yuPlq5lUDRQDVAtUK4BUENQCA&amp;oe=gb2312&amp;dt=1192819388296&amp;lmt=1192819388&amp;format=300x250_as&amp;output=html&amp;correlator=1192819388281&amp;channel=2735220158&amp;url=http%3A%2F%2Fyzkzoo.5d6d.com%2Fviewthread.php%3Ftid%3D70%26page%3D1%26extra%3Dpage%253D1&amp;color_bg=FFFFFF&amp;color_text=000000&amp;color_link=0000FF&amp;color_url=008000&amp;color_border=336699&amp;ad_type=text_image&amp;region=_google_cpa_region_&amp;ref=http%3A%2F%2Fyzkzoo.5d6d.com%2Fpost.php%3Faction%3Dedit%26fid%3D16%26tid%3D70%26pid%3D70%26page%3D1%26extra%3Dpage%253D1&amp;cc=100&amp;ga_vid=1025434795.1192631677&amp;ga_sid=1192817968&amp;ga_hid=1527165455&amp;ga_fc=true&amp;flash=8&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_his=5&amp;u_java=true"></iframe>

<iframe style="WIDTH: 82.23%; HEIGHT: 74px" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4577827332549849&amp;dt=1192818497343&amp;lmt=1192818497&amp;format=468x60_as&amp;output=html&amp;correlator=1192818497343&amp;channel=1741427766&amp;url=http%3A%2F%2Fyzkzoo.5d6d.com%2Fthread-68-1-1.html&amp;color_bg=FFFFFF&amp;color_text=000000&amp;color_link=0000FF&amp;color_url=008000&amp;color_border=336699&amp;ad_type=text_image&amp;ref=http%3A%2F%2Fyzkzoo.5d6d.com%2Fforumdisplay.php%3Ffid%3D16%26page%3D1&amp;ui=rc%3A6&amp;cc=100&amp;ga_vid=1025434795.1192631677&amp;ga_sid=1192817968&amp;ga_hid=1000484876&amp;ga_fc=true&amp;flash=8&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_his=6&amp;u_java=true"></iframe>

<iframe style="WIDTH: 58.41%; HEIGHT: 156px" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4577827332549849&amp;dt=1192819750656&amp;lmt=1192819750&amp;prev_fmts=468x60_as%2C468x15_0ads_al_s%2C234x60_as&amp;format=200x90_0ads_al_s&amp;output=html&amp;correlator=1192819750437&amp;channel=1741427766&amp;pv_ch=1741427766%2B&amp;url=http%3A%2F%2Fyzkzoo.5d6d.com%2Fthread-68-1-1.html&amp;color_bg=FFFFFF&amp;color_text=000000&amp;color_link=0000FF&amp;color_url=008000&amp;color_border=336699&amp;ref=http%3A%2F%2Fyzkzoo.5d6d.com%2Fforum-16-1.html&amp;cc=100&amp;ga_vid=1025434795.1192631677&amp;ga_sid=1192817968&amp;ga_hid=1871659779&amp;ga_fc=true&amp;flash=8&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_his=2&amp;u_java=true"></iframe> 

 

相关文章推荐

C++二叉树实验

二叉树实验报告

  • 2014-02-13 13:34
  • 212KB
  • 下载

【数据结构实验】二叉树的建立以及遍历

二叉树:结点的度最大值是2,即每个结点的子树数目只可能为0、1、2。 如果结点有两棵子树,则这两棵子树有次序关系,分别称为左子树和右子树。左、右子树的根结点分别 称为其双亲结点的左儿子和右儿子。度...

数据结构实验之查找二:平衡二叉树

think: 1 今天学习了平衡二叉树的知识,感觉还是不理解,自己照着部分模板敲了代码,但是也不知道自己的学习方法对不对,不知道自己是不是有点拔苗助长的滋味,数据结构树的部分,从最开始的二叉树的遍历...

数据结构实验之二叉树的遍历

【实验内容】创建一个二叉树,对这棵动态二叉树进行分析,将其用静态二叉链表表示。二叉树的动态二叉链表结构中的每个结点有三个字段:data,lchild,rchild。静态二叉链表是用数组作为存储空间,每...

二叉树实验

  • 2013-04-29 00:55
  • 97KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)