示例#1
0
文件: 001.c 项目: minggr/backup
static void tree2link(struct node *root, struct node **head, struct node **tail)
{
	struct node *h, *t;	

	if (!root) {
		*head = *tail = NULL;
		return;
	}

	tree2link(root->left, &h, &t);	
	if (h)
		*head = h;
	else
		*head = root;
	root->left = t;
	if (t)
		t->right = root;

	tree2link(root->right, &h, &t);	
	if (t)
		*tail = t;
	else
		*tail = root;
	root->right = h;
	if (h)
		h->left = root;
}
示例#2
0
文件: 001.c 项目: minggr/backup
int main()
{
	struct node *h, *t;

	init();
	tree2link(root, &h, &t);
	print_link(h);

	return 0;
}
示例#3
0
文件: 001.c 项目: minggr/backup
static void tree2link(struct node *root, struct node **head, struct node **tail)
{
	struct node *h, *t;	

	if (root->left) {
		tree2link(root->left, &h, &t);	
		*head = h;
		root->left = t;
		if (t)
			t->right = root;
	} else
		*head = root;

	if (root->right) {
		tree2link(root->right, &h, &t);	
		*tail = t;
		root->right = h;
		if (h)
			h->left = root;
	} else
		*tail = root;
}
int main()
{
   printf("Please input the values of nodes seperated by space with -1 denotes termination\n");
   BTree root=(BTree)malloc(sizeof(BiTNode));
   root->left=NULL;
   createSortedTree(&(root->left));
   printf("create done! print\n");
   printf("in order sequence:\n");
   inOrderTraverse(root->left);
   printf("\npost order sequence(1):\n");
   postOrderTraverse(root->left);
   printf("\npost order sequence(2):\n");
   postOrderTraverse2(root->left);
   printf("\n The level sequenece is:\n");
   levelTraverse(root->left);
   printf("\nlink view:\n");
   linkTraverse(tree2link(root->left));
}