sicily Left Rotation

题目要求为实现左旋,题目很简单,不过第一次写左旋,当练手啦~

由题意得需要有一个BinarytNode* 型的数据temp用于进行交换。题目要求将根节点的左节点旋转为根节点,然后将根节点变成左节点。


#include<iostream>
using namespace std;
typedef int Comparable;
struct BinaryNode
{
	Comparable data;
	BinaryNode *left;
	BinaryNode *right;

	BinaryNode( const Comparable & theElement, BinaryNode *lt = NULL, BinaryNode *rt=NULL )
		: data( theElement ), left( lt ), right( rt ) { }
}; 

void rotateL(BinaryNode* &root) {
	//Left rotation, assuming root and the right subtree of root are not empty.
	BinaryNode* temp;
	temp = root;
	root = root->right;
	temp->right = root->left;
	root->left = temp;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值