文章

5

粉丝

0

获赞

21

访问

636

头像
二叉搜索树 题解:建立二叉树,都前序遍历输出成字符串,strcmp比较是否相同
P1317 浙江大学机试题
发布于2026年2月13日 11:06
阅读数 44

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct node{
    int data ;
    struct node *lchild,*rchild;
}BitTree;

BitTree* InsertBitTree(BitTree* T,int x)
{
    if(T==NULL)
    {
        T = (BitTree*)malloc(sizeof(BitTree));
        T->data = x;
        T->lchild=NULL;
        T->rchild=NULL;
    }
    else if(x < T->data) T->lchild = InsertBitTree(T->lchild, x);
    else if(x > T->data) T->rchild = InsertBitTree(T->rchild, x);
    return T;
}

void PreorderTraverse(BitTree *T,char *str,int *pos)
{
    if(T!=NULL)
    {
        str[(*pos)++]=T->data;
       &...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发