⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree1.txt

📁 二叉树的算法
💻 TXT
字号:
二叉树,先序建立,中序遍历
<bitree.h>
#include <lstack-t.h>
void cr_bitree(struct bitnode **t)
{
 int data;
 scanf("%d",&data);
 if(data==0)
 {
  printf("\nnext\n");
  (*t)=NULL;
 }
 else
 {
  (*t)=(struct bitnode *)malloc(sizeof(struct bitnode));
  (*t)->data=data;
  printf("\nnode\n");
  cr_bitree(&((*t)->lchild));
  cr_bitree(&((*t)->rchild));
 }
}
void iot_bitree(struct bitnode **t)
{
 lstack s;
 s.top=(stacknode*)malloc(sizeof(stacknode));
 s.top->next=NULL;
 while((*t)!=NULL||!stackempty(s))
 {
  if((*t)!=NULL)
  {
   push(s,(*t));
   (*t)=(*t)->lchild;
  }
  else
  {
   (*t)=pop(s);
   printf("%d",(*t)->data);
   (*t)=(*t)->rchild;
  }
 }
}
<lstack-t.h>#include <stdlib.h>
struct bitnode
{
 int data;
 struct bitnode *lchild,*rchild;
};
typedef struct stacknode
{
 struct bitnode  *data;
 struct stacknode *next;
}stacknode;
typedef struct lstack
{
 stacknode *top;
}lstack;

void push(struct lstack s,struct bitnode *e )
{
 stacknode *new;
 new=(struct stacknode*)malloc(sizeof(struct stacknode));
 new->data=e;
 new->next=s.top->next;
 s.top->next=new;
}

struct bitnode *pop(lstack s)
{
 struct bitnode *e;
 struct stacknode *temp;
 temp=s.top->next;
 e=temp->data;
 s.top->next=temp->next;
 free(temp);
 return(e);
}

int stackempty(lstack s)
{
 if(s.top->next==NULL)
  return(1);
 return(0);
}
struct bitnode *gettop(lstack s)
{
 return(s.top->next->data);
}

<bitree.c>

#include <stdio.h>
#include <bitree.h>
void main()
{
 struct bitnode **t;
 cr_bitree(t);
 iot_bitree(t);
 printf("\n");
 getchar();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -