Interview question: pre-order traversal of a binary tree

typedef struct _TreeNode
{
	struct _TreeNode* pLeft;
	struct _TreeNode* pRight;
	int data;
} TreeNode, *PTreeNode; 

void BinaryTreePreorderTraversal(PTreeNode root)
{
	static int max;

	if(!root)
	{
		return;
	}

	printf("%d\t", root->data);
	BinaryTreePreorderTraversal(root->pLeft);
	BinaryTreePreorderTraversal(root->pRight);
}

Leave a Reply

Your email address will not be published. Required fields are marked *