二叉树 递归

最近写二叉树一个小结
typedef struct node {
	int data;
	struct node *left_subtree,
		*right_subtree;
} node, *bi_tree;

int a[30] = { 0 };
int b[30] = { 0 };
int total = 0;

bi_tree CreatTree(int*indata,int parent)
{
	bi_tree T;
	int temp1 = 0;
	int temp2 = 0;
	int flag = 0;

	T = (bi_tree)malloc(sizeof(node));
	T->data =parent;
	if(parent==0)
		return T;
	//cout << parent << " ";
	for (int i = 0;i < indata[1];i++)
	{
		if ((indata[2 * i + 4] == parent)&&(flag==0))
		{
			temp1 = indata[2 * i + 5];
			flag++;
		}
		if ((indata[2 * i + 4] == parent) && (flag == 1)&&(indata[2 * i + 5] !=temp1))
		{
			temp2 = indata[2 * i + 5];
			flag++;
		}
	}
	flag = 0;
	if(temp1!=0)
		T->left_subtree = CreatTree(indata,temp1);
	else
		T->left_subtree = CreatTree(indata, 0);
	if (temp2 != 0)
		T->right_subtree = CreatTree(indata,temp2);
	else
		T->right_subtree = CreatTree(indata, 0);
	return T;
}

void puttree(bi_tree t) 
{
	if (t->data == 0)
		return;
	else
	{
		puttree(t->left_subtree);
		//cout << t->data << " ";
		puttree(t->right_subtree);
	}
}


int main()
{
	int* srcData;
	bi_tree T;
	T = CreatTree(srcData, 1);
	//puttree(T);

	getchar();
    return 0;
}
这个是全排列
#include
using namespace std;
int a[100];
void dfs(int cur,int n)//cur表示目前正在填的数,n表示总共要填的数 
{
    if(cur==n)//递归边界,说明填完了 
    {
        for(int i=0;i>n;
    dfs(0,n);
    return 0;
}

你可能感兴趣的:(二叉树 递归)