二叉树遍历

/*
字符串常用函数
1、	strlen(char const *string)
2.		strcpy(char *dst, char const *src )
3,		strcat(char *dst, char const *src)
4,		strcmp(char const *s1 , char const *s2)

5,		strncpy(char * dst, char const *src , int n)
6,		strncat(char *dst, char const *src, int n)
7,		strncmp(char const *s1 , char const *s2,int n)

8,		strchr(char * src , char c) //字符c第一次出现的位置
9,		strrchr(char *src, char c)//字符c最后一次出现的位置

10,	strpbrk(char const *str, char const *group)//查找字符串中任何一个字符第一次出现的位置
11,	strstr(char const *s1, char const *s2)//在s1中查找子串s2
12,	strtok(char const *src, char const *token)//分解字符串为一组字符串。s为要分解的字符串,delim为分隔符字符串。首次调用时,s指向要分解的字符串,之后再次调用要把s设成NULL。
*/

#include<stdio.h>
struct node
{
int num;
struct node *lc;
struct node *rc;
} node;

void preorder(struct node * root)
{
	if(root==NULL) return ;
	printf("%d ",root->num);
	preorder(root->lc);
	preorder(root->rc);
}

void middleorder(struct node * root)
{
	if(root==NULL) return ;
	middleorder(root->lc);
	printf("%d ",root->num);
	middleorder(root->rc);
}

// 元素查找

int search(struct node * root, int x)
{
	//if(root==NULL) return  ;
	if(root->num==x) return x;
	else if(root->lc !=null)
		return search(root->lc,x);
	else if(root ->rc!=null)
		return search(root->rc,x);
}

//求深度

int high(struct node * root,int h)
{
	int lh,rh,h
	if(root==null)  h=0 ;
	else
	{
		lh=high(root->lc);
		rh=high(root->rc);
		h=(lh>rh?lh:sh)+1;
	}
	return h;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值