//二叉树操作
#include"stdio.h"
#include"stdlib.h"
typedef struct node{
char data;
struct node *lchild,*rchild;
}bintnode;
typedef bintnode *bintree;
typedef struct stack
{
bintree data[100];
int tag[100];
int top;
}stack;
//压栈
void push(stack *s, bintree t)
{
s->data[s->top]=t;
s->top++;
}
//出栈
bintree pop(stack *s)
{
if(s->top!=0)
{
s->top--;
return (s->data[s->top]);
}
else
return NULL;
}
//创建(前序)
bintree creat()
{
char a;
bintree t;
a=getchar();
if(a=='#')
t=NULL;
else
{
t=(bintnode*)malloc(sizeof(bintnode));
t->data=a;
t->lchild=creat();
t->rchild=creat();
}
return t;
}
//查找
bintree seek(bintree t, char x)
{
bintree p;
if(t==NULL) return NULL;
else
{
if(t->data==x) return t;
else
{
p=seek(t->lchild,x);
if(p) return p;
else
return seek(t->rchild,x);
}
}
数据结构————二叉树操作(C语言)
最新推荐文章于 2026-04-09 22:35:13 发布
本文详细介绍了如何使用C语言进行二叉树的各种操作,包括创建、插入、删除节点等,通过实例展示了具体实现过程。

&spm=1001.2101.3001.5002&articleId=84031909&d=1&t=3&u=c71d862e22224ccf9eb6fa17b3f9bb06)
1879

被折叠的 条评论
为什么被折叠?



