/*
字符串常用函数
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;
}
二叉树遍历
最新推荐文章于 2022-10-15 13:55:02 发布