当前位置: 首页>>代码示例>>C++>>正文


C++ rotateRight函数代码示例

本文整理汇总了C++中rotateRight函数的典型用法代码示例。如果您正苦于以下问题:C++ rotateRight函数的具体用法?C++ rotateRight怎么用?C++ rotateRight使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rotateRight函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

/*
void MovieTree::fixUpAdd(Movie*)

Description:
Private method used to balance the tree after adding a movie.

Example:
MovieTree tree;
tree.addMoviebyTitle("Back to the Future", 1985, 96, 5);

Precondition:
The ends of the tree are nil. The tree is arranged correctly.

Postcondition:
The tree will be balanced.
*/
void MovieTree::fixUpAdd(Movie *x)
{
    x->isRed = true;

    while (x != root && x->parent->isRed) {
        if (x->parent == x->parent->parent->left) {
            Movie *y = x->parent->parent->right;

            if (y->isRed) {
                x->parent->isRed = false;
                y->isRed = false;
                x->parent->parent->isRed = true;
                x = x->parent->parent;
            } else {
                if (x == x->parent->right) {
                    x = x->parent;
                    rotateLeft(x);
                }

                x->parent->isRed = false;
                x->parent->parent->isRed = true;
                rotateRight(x->parent->parent);
            }
        } else {
            Movie *y = x->parent->parent->left;

            if (y->isRed) {
                x->parent->isRed = false;
                y->isRed = false;
                x->parent->parent->isRed = true;
                x = x->parent->parent;
            } else {
                if (x == x->parent->left) {
                    x = x->parent;
                    rotateRight(x);
                }

                x->parent->isRed = false;
                x->parent->parent->isRed = true;
                rotateLeft(x->parent->parent);
            }
        }
    }

    root->isRed = false;
}
开发者ID:AdamEParnes,项目名称:Anderson_CSCI2270_FinalProject,代码行数:62,代码来源:MovieTree.cpp

示例2: strcmp

void C_galgas_type_descriptor::recursiveInsert (C_galgas_type_descriptor * & ioRootPtr,
                                                C_galgas_type_descriptor * inDescriptor,
                                                bool & ioExtension) {
  if (ioRootPtr == NULL) {
    ioExtension = true ;
    ioRootPtr = inDescriptor ;
  }else{
    const int32_t comparaison = strcmp (ioRootPtr->mGalgasTypeName, inDescriptor->mGalgasTypeName) ;
    if (comparaison > 0) {
      recursiveInsert (ioRootPtr->mPreviousType, inDescriptor, ioExtension) ;
      if (ioExtension) {
        ioRootPtr->mBalance++;
        if (ioRootPtr->mBalance == 0) {
          ioExtension = false;
        }else if (ioRootPtr->mBalance == 2) {
          if (ioRootPtr->mPreviousType->mBalance == -1) {
            rotateLeft (ioRootPtr->mPreviousType) ;
          }
          rotateRight (ioRootPtr) ;
          ioExtension = false;
        }
      }
    }else if (comparaison < 0) {
      recursiveInsert (ioRootPtr->mNextType, inDescriptor, ioExtension) ;
      if (ioExtension) {
        ioRootPtr->mBalance-- ;
        if (ioRootPtr->mBalance == 0) {
          ioExtension = false ;
        }else if (ioRootPtr->mBalance == -2) {
          if (ioRootPtr->mNextType->mBalance == 1) {
            rotateRight (ioRootPtr->mNextType) ;
          }
          rotateLeft (ioRootPtr) ;
          ioExtension = false;
        }
      }
    }else{
      ioExtension = false;
      C_String errorMessage ;
      errorMessage << "FATAL ERROR (type '@" << inDescriptor->mGalgasTypeName << "' already defined)" ;
      fatalError (errorMessage, __FILE__, __LINE__) ;
    }
  }
}
开发者ID:jiguosong,项目名称:trampoline,代码行数:44,代码来源:C_galgas_type_descriptor.cpp

示例3: fprintf

int AVLTree::ins(AVLNode* &p, FFSObject *e) {
    int deltaH = 0;
    if (p == NULL) {
	p = new AVLNode;
#ifdef _DEBUG_AVL
	AVLTree::tree_cnt++;
#endif
	p->elem = e;
	p->bal = 0;
	p->left = p->right = NULL;
	deltaH = 1;  /* tree hight increased by 1 */
#ifdef _DEBUG_AVL
	fprintf(stderr, "added %s to AVLTree (count %d)\n", 
		e->getName(), count);
#endif
    } else if (compareType == AVL_CMP_NAME
	       ? e->compareName(p->elem) > 0
	       : e->compareAll(p->elem) > 0) {
	if (ins(p->right, e)) {
	    p->bal++; /* height of right subtree increased */
	    if (p->bal == 1) {
		deltaH = 1;
	    } else if (p->bal == 2) {
		if (p->right->bal == -1) {
		    rotateRight(p->right);
		}
		rotateLeft(p);
	    }
	}
    } else /* if (e->compareAll(p->elem) <= 0)*/ {
	if (ins(p->left, e)) {
	    p->bal--;
	    if (p->bal == -1) {
		deltaH = 1;
	    } else if (p->bal == -2) {
		if (p->left->bal == 1) {
		    rotateLeft(p->left);
		}
		rotateRight(p);
	    }
	}
    }
    return deltaH;
}
开发者ID:alaeri,项目名称:3dfm,代码行数:44,代码来源:AVLTree.cpp

示例4: insertSplay

/*
	Notes:
	* tree insertion using splay method
	* produces different results to the visualiser

*/
Link insertSplay(Link n, int value)
{
	if (n == NULL) { return newNode(value); }

	if (value < n->value){ // right rotations
		if (n->left == NULL){ // left branch is NULL
			n->left = newNode(value);
		}

		else if (value < n->left->value){ // zig zig left
			n->left->left = insertSplay(n->left->left, value);
			// n->left = rotateRight(n->left);
			n = rotateRight(n);
		}

		else{ // zig zag left
			n->left->right = insertSplay(n->left->right, value);
			n->left = rotateLeft(n->left);
		}

		n = rotateRight(n);
	}

	if (value > n->value){ // left rotations
		if (n->right == NULL){
			n->right = newNode(value);
		}

		else if (value > n->right->value){ // zig zig right
			n->right->right = insertSplay(n->right->right, value);
			// n->right = rotateLeft(n->right);
			n = rotateLeft(n);
		}

		else{ // zig zag right
			n->right->left = insertSplay(n->right->left, value);
			n->right = rotateRight(n->right);
		}
		
		n = rotateLeft(n);
	}

	return n;
}
开发者ID:matthewT53,项目名称:Data-structures-and-algorithms,代码行数:50,代码来源:splay.c

示例5: armTranslateDPI_MoveImm

void armTranslateDPI_MoveImm(ARM_PseudoInstruction& pi,
                             DPI_Opcode op, bool s, bool a, ARM_Condition cond,
                             uint8_t Rd,
                             uint8_t immed, uint8_t rotate_amount) {
  pi.f = arm_dpi_move_table[a][s][op-FIRST_MOVE][0][Rd==ARM_CPU::PC];
  pi.args.dpi_imm.Rd = Rd;
  pi.args.dpi_imm.set_carry = rotate_amount;
  pi.args.dpi_imm.immed = rotateRight(immed,rotate_amount);
  pi.args.any.cond = cond;
}
开发者ID:kinhoa122345,项目名称:virtualsoc-wcdma,代码行数:10,代码来源:armpi.cpp

示例6: insertAt

	// -1 --- неуспешно включване, елементът вече го има
	// 0  --- успешно включване, но няма промяна във височината
	// 1  --- успешно включване и има увеличение на височината с 1
	int insertAt(P p, T const& x) {
		if (!p) {
			// дъно
			BinaryTree<AVL>::assignFrom(p, AVL(x));
			return 1;
		}
		// p --- валидна позиция
		if ((*p).data() == x)
			// Грешка! x вече го има
			return -1;
		// p && *p != x
		int result;
		if (x < (*p).data()) {
			// вмъкваме наляво
			result = insertAt(-p, x);
			if (result == 1) {
				(*p).balance()--;
				if ((*p).balance() == -2) {
					if ((*-p).balance() == 1)
						rotateLeft(-p);
					rotateRight(p);
					result = 0;
				}
			}
		} else {
			// вмъкваме надясно
			result = insertAt(+p, x);
			if (result == 1) {
				(*p).balance()++;
				if ((*p).balance() == 2) {
					if ((*+p).balance() == -1)
						rotateRight(+p);
					rotateLeft(p);
					result = 0;
				}
			}
		}
		// ако сме вмъкнали успешно и балансът се е получил 0
		// значи нямаме промяна във височината
		if (result >= 0 && (*p).balance() == 0)
			result = 0;
		return result;
	}
开发者ID:triffon,项目名称:sdp-2015-16,代码行数:46,代码来源:avltree.cpp

示例7: while

bool ExpressionTreeUtils::fixExprPrecedence(Expression*& top, Expression* e)
{
	if ( dynamic_cast<Value*> (e)) return false;
	if ( dynamic_cast<Empty*> (e)) return false;

	Operator* op = dynamic_cast<Operator*> (e);

	bool more_iterations_needed = true;
	while (more_iterations_needed)
	{
		more_iterations_needed = false;

		// Fix all children
		for (int operand = 0; operand < op->size(); ++operand)
			more_iterations_needed = fixExprPrecedence(top, op->at(operand)) || more_iterations_needed;
	}

	//Look left
	if (op->descriptor()->prefix().isEmpty())
	{
		Operator* left = dynamic_cast<Operator*> (op->first());
		if (left && left->descriptor()->postfix().isEmpty())
		{
			if (op->descriptor()->precedence() < left->descriptor()->precedence() // Must rotate because of precedence

				 // Must rotate because of associativity. This assumes that the associativity of different operators at the same precedence level is the same.
				 || ( (op->descriptor()->precedence() == left->descriptor()->precedence()) && op->descriptor()->associativity() == OperatorDescriptor::RightAssociative)
				 )
			{
				rotateRight(top, left, op);
				return true;
			}
		}
	}

	//Look right
	if (op->descriptor()->postfix().isEmpty())
	{
		Operator* right = dynamic_cast<Operator*> (op->last());
		if (right && right->descriptor()->prefix().isEmpty())
		{
			if (op->descriptor()->precedence() < right->descriptor()->precedence() // Must rotate because of precedence

				 // Must rotate because of associativity. This assumes that the associativity of different operators at the same precedence level is the same.
				 || ( (op->descriptor()->precedence() == right->descriptor()->precedence()) && op->descriptor()->associativity() == OperatorDescriptor::LeftAssociative)
				 )
			{
				rotateLeft(top, right, op);
				return true;
			}
		}
	}

	return false;
}
开发者ID:helandre,项目名称:Envision,代码行数:55,代码来源:ExpressionTreeUtils.cpp

示例8: main

int main(void)
{
	setupADC();	
	setupStepperMotor();
	startTimer();

	USART_init();
	
	mouse.velocity = 0;
	mouse.maxVelocity = 5000;
	mouse.acceleration = 2000;
	mouse.deceleration = 10000;

	enableDrive(1);
	turnOnTimers(1,1);
	
	for(int i = 0; i < 10; i++)
	{		
		int right = isWallRight();
		int front = isWallFront();
		int left = isWallLeft();
		
		if(!right)
		{
			rotateRight();
		}
		else if(front && !left)
		{
			rotateLeft();
		}
		else if(front)
		{
			moveBackwardsAndCorrect();
		}	
		
		if(left && right)		
			mouse.IR_CORRECT = 20;
		
		moveForwardAndStop();
		
		mouse.IR_CORRECT = 0;
		
		
	}

	
	turnOnTimers(0, 0);
	enableDrive(0);
	
	
	while(1==1)
	{

	}	
}
开发者ID:rohankaps123,项目名称:Micromouse2014,代码行数:55,代码来源:main.c

示例9: adjustBalance

void AVLTreeIndex::restoreBalance(AVLTreeNode *parent, AVLTreeNode *newNode)
{
    // case 1: parent DNE, newNode unbalances
    if (parent == NULL) {
        if (newNode->key < root->key) root->balance = biasleft; // newNode inserted left of root
        else root->balance = biasright; // newNode inserted right of root
        adjustBalance(root, newNode);
    }

    // case 2: insertion of newNode in opposite subtree of parent, balances parent
    else if (((parent->balance == biasleft) && (newNode->key.compare(parent->key) > 0)) ||
             ((parent->balance == biasright) && (newNode->key.compare(parent->key) < 0))) {
        parent->balance = balanced;
        adjustBalance(parent, newNode);
    }

    // case 3: insertion of newNode in right child of parent
    else if (parent->balance == biasright) {
        if (newNode->key > parent->right->key) { // insertion into right subtree of right child, single rotation left
            parent->balance = balanced;
            rotateLeft(parent);
            adjustBalance(parent->parent, newNode);
        } else if (newNode->key < parent->right->key) { // insertion into left subtree of right child, double rotation left
            rotateRight(parent->right);
            rotateLeft(parent);
            adjustRL(parent, newNode);
        }
    }

    // case 4: insertion of newNode in left child of parent
    else if (parent->balance == biasleft) {
        if (newNode->key < parent->left->key) { // insertion into left subtree of left child, single rotation right
            parent->balance = balanced;
            rotateRight(parent);
            adjustBalance(parent->parent, newNode);
        } else if (newNode->key < parent->right->key) { // insertion into right subtree of left child, double rotation right
            rotateLeft(parent->left);
            rotateRight(parent);
            adjustLR(parent, newNode);
        }
    }
}
开发者ID:conradhappeliv,项目名称:schoolwork,代码行数:42,代码来源:avltreeindex.cpp

示例10: rotate

Node* rotate(Node* gr, Node* par, Node* ch)
{
    if (par->left == ch) 
    {
        return rotateRight(gr, par, ch);
    } 
    else 
    {
        return rotateLeft(gr, par, ch);
    }
}
开发者ID:kngako,项目名称:ComputationalExperiment,代码行数:11,代码来源:module_1.cpp

示例11: delete_min_rc

static spltreeNode_t* delete_min_rc(spltreeNode_t* splnode, spltreeNode_t** min) {
	if(!splnode->left) {
		*min = splnode;
		return splnode->right;
	}
	splnode->left = delete_min_rc(splnode->left,min);
	if(!splnode->left) {
		return splnode;
	}
	return rotateRight(splnode);
}
开发者ID:fritzprix,项目名称:cdsl,代码行数:11,代码来源:cdsl_spltree.c

示例12: backToZone

void backToZone(){
	rotateRight(25,50);
	motor[back]=-25;
	drive(-50);
	while(nMotorEncoder[back]>-30);
	motor[back]=0;
	while(nMotorEncoder[back]<-20);
	drive(50);
	wait1Msec(200);
	drive(0);
}
开发者ID:ecgrobotics,项目名称:FTC-731,代码行数:11,代码来源:autoOLD.c

示例13: switch

bool Block::rotate(int direction) {
	switch (direction) {
	case DIRECTION_LEFT:
		return rotateLeft();
		break;
	case DIRECTION_RIGHT:
		return rotateRight();
		break;
	}
	return false;
}
开发者ID:Gnash,项目名称:allegris,代码行数:11,代码来源:Block.cpp

示例14: while

void QMapDataBase::rebalance(QMapNodeBase *x)
{
    QMapNodeBase *&root = header.left;
    x->setColor(QMapNodeBase::Red);
    while (x != root && x->parent()->color() == QMapNodeBase::Red) {
        if (x->parent() == x->parent()->parent()->left) {
            QMapNodeBase *y = x->parent()->parent()->right;
            if (y && y->color() == QMapNodeBase::Red) {
                x->parent()->setColor(QMapNodeBase::Black);
                y->setColor(QMapNodeBase::Black);
                x->parent()->parent()->setColor(QMapNodeBase::Red);
                x = x->parent()->parent();
            } else {
                if (x == x->parent()->right) {
                    x = x->parent();
                    rotateLeft(x);
                }
                x->parent()->setColor(QMapNodeBase::Black);
                x->parent()->parent()->setColor(QMapNodeBase::Red);
                rotateRight (x->parent()->parent());
            }
        } else {
            QMapNodeBase *y = x->parent()->parent()->left;
            if (y && y->color() == QMapNodeBase::Red) {
                x->parent()->setColor(QMapNodeBase::Black);
                y->setColor(QMapNodeBase::Black);
                x->parent()->parent()->setColor(QMapNodeBase::Red);
                x = x->parent()->parent();
            } else {
                if (x == x->parent()->left) {
                    x = x->parent();
                    rotateRight(x);
                }
                x->parent()->setColor(QMapNodeBase::Black);
                x->parent()->parent()->setColor(QMapNodeBase::Red);
                rotateLeft(x->parent()->parent());
            }
        }
    }
    root->setColor(QMapNodeBase::Black);
}
开发者ID:KDE,项目名称:android-qt5-qtbase,代码行数:41,代码来源:qmap.cpp

示例15: while

void AVL_Tree::balance(Node* city, int counter) {

    Node* check;
    	while(city){
            counter++;
    		if(city->getBalance() == 0)
    			break;

    		else if(city->getBalance() == 2){
    			check = city->getRight();

                counter++;
    			if(city != m_root){

    				if(city -> getParent() -> getRight() == city)
    					city -> getParent() -> adjustBalance(-1);
    				else
    					city -> getParent() -> adjustBalance(1);
    			}

                counter++;
    			if(check->getBalance()==-1)
    				rotateRL(city);
    			else
    				rotateLeft(city);
    			city -> setBalance(0);
    			check -> setBalance(0);
    		}

    		else if(city -> getBalance() == -2){
                counter++;
    			if(city != m_root){

                    counter++;
    				if(city -> getParent() -> getRight() == city)
    					city -> getParent() -> adjustBalance(-1);
    				else
    					city -> getParent() -> adjustBalance(1);
    			}
    			check = city -> getLeft();

                counter++;
    			if(check -> getBalance() == 1)
    				rotateLR(city);
    			else
    				rotateRight(city);
    			city -> setBalance(0);
    			check -> setBalance(0);
    		}
    		city = city -> getParent();
    	}
        std::cout << "Comparison count for this function is " << counter << "\n";
}//end balance
开发者ID:e-nichols,项目名称:EECS_560,代码行数:53,代码来源:AVL_Tree.cpp


注:本文中的rotateRight函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。