二叉排序树的实现:分别以顺序表和二叉链表作为存储结构,实现二叉排序树。基本操作有查找、插入、删除。

2024-11-03 21:11:16
推荐回答(2个)
回答1:

楼主注意用顺序表作二叉树的存储结构的结点的结构, 结点的地址是顺序表的索引值
时间复杂度是 n
C/C++ code#include

typedef struct Nod
{
char d;
int left, right;
}Node;

void inorder(Node t[], int root)
{
if(root!=-1)
{
inorder(t, t[root].left);
printf("%c ", t[root].d);
inorder(t, t[root].right);
}
}
void main()
{
Node t[3] ={{'r', 1, 2} , {'1', -1, -1}, {'2', -1, -1}};
inorder(t, 0);

回答2:

BinTree root; int i,depth; printf(