现在的位置: 首页 > 综合 > 正文

二叉搜索树镜像

2014年01月26日 ⁄ 综合 ⁄ 共 370字 ⁄ 字号 评论关闭
struct node
{
	int val;
	node* p_left;
	node* p_right;
	node(int t)
	{
		val = t;
		p_left = p_right = 0;
	}
};

typedef struct node* link;

void insert_bst(link &h, int t)
{
	if (0 == h) 
	{
		h = new node(t);
		return;
	}

	if (t < h->val) insert_bst(h->p_left, t);
	else insert_bst(h->p_right, t);
}

void mirror_bst(link h)
{
	if (0 == h) return;
	
	link p_temp = h->p_left;
	h->p_left = h->p_right;
	h->p_right = p_temp;
	
	mirror_bst(h->p_left);
	mirror_bst(h->p_right);
}

抱歉!评论已关闭.