두 갈래 나무가 차례로 돌아오다.

1654 단어
 
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;
}

좋은 웹페이지 즐겨찾기