Node<Key, Val>* InsertInternal(Node<Key, Val>* h, Key key, Val val){ if (h == NULL){ ++num_; return new Node<Key, Val>(key, val); } if (IsRED(h->left) && IsRED(h->right)){ FlipColor(h); } if (key == h->key){ h->val = val; } else if (Comp()(key, h->key)){ h->left = InsertInternal(h->left, key, val); } else { h->right = InsertInternal(h->right, key, val); } if (IsRED(h->right)){ h = RotateLeft(h); } if (IsRED(h->left) && IsRED(h->left->left)){ h = RotateRight(h); } return h; }
//************************************************** // NAME: RotateRight // DESCRIPTION: Robot rotates over the center // PARAMETERS: - speed->Motor speed // - angle->Rotation angle //************************************************** void Motor::RotateRight(byte speed, int angle) { unsigned long time,timeout; byte count; byte encoder; ReduceInertia(); count = angle/(2*ENCODER_ANGLE); encoder = digitalRead(ENC_L); time=millis(); RotateRight(speed); while (count > 0) { while (encoder == digitalRead(ENC_L)) { timeout=millis(); if (timeout - time > MAX_TIMEOUT) { return; } } encoder=digitalRead(ENC_L); count--; time=millis(); } ReduceInertia(); }
Node<Key, Val>* DeleteInternal(Node<Key, Val>* h, Key key){ if (h == NULL) return NULL; if (Comp()(key, h->key)){ if (!IsRED(h->left) && h->left != NULL && !IsRED(h->left->left)){ h = MoveREDLeft(h); } h->left = DeleteInternal(h->left, key); } else { if (IsRED(h->left)){ h = RotateRight(h); } if ((key == h->key) && (h->right == NULL)){ return NULL; } if (!IsRED(h->right) && h->right != NULL && !IsRED(h->right->left)){ h = MoveREDRight(h); } if (key == h->key){ Node<Key, Val>* min_node = GetMin(h->right); h->key = min_node->key; h->val = min_node->val; h->right = DeleteMin(h->right); } else { h->right = DeleteInternal(h->right, key); } } return FixUp(h); }
void CBinaryTree::AddNode(int N) { CNode *pNode,*pParent=NULL,*pNewNode; pNode=LocateNode(N,pRoot); pParent=LocateParent(N,pRoot); if(pParent==NULL) pRoot=new CNode(N); else { if(pNode==NULL) { pNewNode=new CNode(N,pParent); if(pParent->GetData()>N) pParent->pLeft=pNewNode; else pParent->pRight=pNewNode; } } while(pParent!=NULL) { int iBF=GetBalancingFactor(pParent->pRight)-GetBalancingFactor(pParent->pLeft); if(iBF<-1 || iBF>1) { if(iBF>0) RotateLeft(pNewNode); else RotateRight(pNewNode); if(pNewNode->pParent==NULL) pRoot=pNewNode; } pParent=pParent->pParent; pNewNode=pNewNode->pParent; } }
void wxPageContainer::OnLeftDClick(wxMouseEvent& event) { wxPageInfo pgInfo; int tabIdx; int where = HitTest(event.GetPosition(), pgInfo, tabIdx); switch(where) { case wxFNB_RIGHT_ARROW: RotateRight(); break; case wxFNB_LEFT_ARROW: RotateLeft(); break; case wxFNB_TAB: if(HasFlag(wxFNB_DCLICK_CLOSES_TABS)) { DeletePage((size_t)tabIdx); } break; case wxFNB_X: { OnLeftDown(event); } break; default: event.Skip(); break; } }
void junction_follow(void){ signed char lineposition=0; unsigned char i=0; unsigned char status=0; lcd_clr(); lcd_goto(0); lcd_putstr("Junction\nCount"); __delay_ms(500); lcd_clr(); while(1){ do{ status=LSA08_ClearJunction(); }while(status==0); jfolo(2); RotateRight(); motor(180,180); __delay_ms(500); do{ lineposition=LSA08_GetPosition(); LED1=1; }while(lineposition>20); Brake(); LED1=0; __delay_ms(100); RotateRight(); motor(180,180); __delay_ms(500); do{ LED1=1; lineposition=LSA08_GetPosition(); }while(lineposition>20); Brake(); LED1=0; __delay_ms(100); } }
void KeyControlledTransitionCharacter_cl::ProcessKeyboardEvents() { if(!m_bKeyboardInputAllowed) return; bool bLeft = m_pInputMap->GetTrigger(CHARACTER_MOVE_LEFT)!=0; bool bRight = m_pInputMap->GetTrigger(CHARACTER_MOVE_RIGHT)!=0; bool bUp = m_pInputMap->GetTrigger(CHARACTER_MOVE_FORWARD)!=0; bool bDown = m_pInputMap->GetTrigger(CHARACTER_MOVE_BACKWARD)!=0; bool bShift = m_pInputMap->GetTrigger(CHARACTER_RUN)!=0; if (bUp) { // Trigger the run/walk actions when CURSOR UP is pressed. // Allow rotating the entity while walking/running if (bShift) Run(); else Walk(); if (bLeft) RotateLeft(); else if (bRight) RotateRight(); } else if (bDown) { // Trigger the walk backward action when CURSOR DOWN is pressed. // Allow rotating the entity while walking backwards WalkBackwards(); if (bLeft) RotateLeft(); else if (bRight) RotateRight(); } else { if (bLeft) RotateLeft(); else if (bRight) RotateRight(); else Stand(); } }
void Calibrate(void){ LSA08_Calibrate(); RotateRight(); motor(180,180); __delay_ms(600); RotateLeft(); __delay_ms(600);__delay_ms(600); RotateRight(); motor(180,180); __delay_ms(600); motor(0,0);Forward(); lcd_clr(); }
Node<Key, Val>* MoveREDRight(Node<Key, Val>* h){ FlipColor(h); if (h->left != NULL && IsRED(h->left->left)){ h = RotateRight(h); FlipColor(h); } return h; }
Node<Key, Val>* MoveREDLeft(Node<Key, Val>* h){ FlipColor(h); if (h->right != NULL && IsRED(h->right->left)){ h->right = RotateRight(h->right); h = RotateLeft(h); FlipColor(h); } return h; }
static void Balance(pNode& p) { if (!p) return; FixHeight(p); if (BalanceFactor(p) == 2) { if (BalanceFactor(p->Right) < 0) RotateRight(p->Right); RotateLeft(p); } if (BalanceFactor(p) == -2) { if (BalanceFactor(p->Left) > 0) RotateLeft(p->Left); RotateRight(p); } }
void NodeBase::insert(NodeBase *head, NodeBase * n) { /* check Red-Black properties */ while (n != head->left && n->parent->color == NodeColor::Red) { auto p = n->parent; auto g = n->parent->parent; if (p == g->left) { NodeBase * u = g->right; if (u && u->color == NodeColor::Red) { p->color = NodeColor::Black; u->color = NodeColor::Black; g->color = NodeColor::Red; n = g; } else { if (n == p->right) { RotateLeft(head, n, p); n = n->left; p = n->parent; } p->color = NodeColor::Black; g->color = NodeColor::Red; RotateRight(head, p, g); } } else { NodeBase * u = g->left; if (u && u->color == NodeColor::Red) { p->color = NodeColor::Black; u->color = NodeColor::Black; g->color = NodeColor::Red; n = g; } else { if (n == n->parent->left) { RotateRight(head, n, p); n = n->right; p = n->parent; } p->color = NodeColor::Black; g->color = NodeColor::Red; RotateLeft(head, p, g); } } } head->left->color = NodeColor::Black; // root }
void RedBlackTree::CheckInsert(RBNode* node) { if(node->parent == m_nil) { node->bRed = false; return; } if(!node->parent->bRed) { return; } if(getUncle(node)->bRed) { node->parent->bRed = false; getUncle(node)->bRed = false; getGrandParent(node)->bRed = true; CheckInsert(getGrandParent(node)); return; } if(node == node->parent->right && node->parent == getGrandParent(node)->left) { RotateLeft(node->parent); node = node->left; } else if(node == node->parent->left && node->parent == getGrandParent(node)->right) { RotateRight(node->parent); node = node->right; } node->parent->bRed = false; getGrandParent(node)->bRed = true; if(node == node->parent->left) { RotateRight(getGrandParent(node)); } else { RotateLeft(getGrandParent(node)); } }
template<typename T, typename KEY> RBTNode<T, KEY> *RBTree<T, KEY>::MoveRedRight(RBTNode<T, KEY> *h) { regaincolors(h); if (isRed(h->pLeft->pLeft)) { h = RotateRight(h); flipcolors(h); } return h; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Copyright (c) Microsoft Corporation. All rights reserved. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include "Core.h" //////////////////////////////////////////////////////////////////////////////////////////////////// void CLR_RT_AVLTree::Initialize() { NATIVE_PROFILE_CLR_CORE(); m_root = NULL; // Entry* m_root; // OwnerInfo m_owner; } CLR_RT_AVLTree::Result CLR_RT_AVLTree::Insert( Entry* newDatum ) { NATIVE_PROFILE_CLR_CORE(); return Insert( m_root, newDatum ); } CLR_RT_AVLTree::Result CLR_RT_AVLTree::Remove( Entry* oldDatum ) { NATIVE_PROFILE_CLR_CORE(); return Remove( m_root, oldDatum ); } CLR_RT_AVLTree::Entry* CLR_RT_AVLTree::Find( Entry* srcDatum ) { NATIVE_PROFILE_CLR_CORE(); Entry* node = m_root; ComparerFtn ftn = m_owner.m_ftn_compare; void* state = m_owner.m_state; while(node) { int cmp = ftn( state, node, srcDatum ); if(cmp == 0) break; if(cmp > 0) { node = node->m_left; } else { node = node->m_right; } } return node; } ////////////////////////////////////////////////// // // Perform counterclockwise rotation. // void CLR_RT_AVLTree::RotateLeft( Entry*& n ) { NATIVE_PROFILE_CLR_CORE(); ////////////////////////// // // // A A // // \ \ // // B => \ // // / \ \ // // C C // // / \ / \ // // B // // / \ // // // ////////////////////////// Entry* top = n; Entry* bottom = top->m_right; top ->m_right = bottom->m_left; bottom->m_left = top; n = bottom; } // // Perform clockwise rotation. // void CLR_RT_AVLTree::RotateRight( Entry*& n ) { NATIVE_PROFILE_CLR_CORE(); ////////////////////////// // // // A A // // / / // // B => / // // / \ / // // C C // // / \ / \ // // B // // / \ // // // ////////////////////////// Entry* top = n; Entry* bottom = top->m_left; top ->m_left = bottom->m_right; bottom->m_right = top; n = bottom; } // // LeftGrown: helper function for avlinsert // // Parameters: // // n Reference to the pointer to a node. This node's left // subtree has just grown due to item insertion; its // "skew" flag needs adjustment, and the local tree // (the subtree of which this node is the root node) may // have become unbalanced. // // Return values: // // RES_OK The local tree could be rebalanced or was balanced // from the start. The parent activations of the avlinsert // activation that called this function may assume the // entire tree is valid. // // RES_BALANCE The local tree was balanced, but has grown in height. // Do not assume the entire tree is valid. // CLR_RT_AVLTree::Result CLR_RT_AVLTree::LeftGrown( Entry*& n ) { NATIVE_PROFILE_CLR_CORE(); Entry* left; Entry* right; switch(n->m_skew) { case SKEW_LEFT: left = n->m_left; if(left->m_skew == SKEW_LEFT) { n ->m_skew = SKEW_NONE; left->m_skew = SKEW_NONE; RotateRight( n ); } else { right = left->m_right; switch(right->m_skew) { case SKEW_LEFT: n ->m_skew = SKEW_RIGHT; left->m_skew = SKEW_NONE; break; case SKEW_RIGHT: n ->m_skew = SKEW_NONE; left->m_skew = SKEW_LEFT; break; default: n ->m_skew = SKEW_NONE; left->m_skew = SKEW_NONE; } right->m_skew = SKEW_NONE; RotateLeft ( n->m_left ); RotateRight( n ); } return RES_OK; case SKEW_RIGHT: n->m_skew = SKEW_NONE; return RES_OK; default: n->m_skew = SKEW_LEFT; return RES_BALANCE; } } ///* // * avlrightgrown: helper function for avlinsert // * // * See avlleftgrown for details. // */ CLR_RT_AVLTree::Result CLR_RT_AVLTree::RightGrown( Entry*& n ) { NATIVE_PROFILE_CLR_CORE(); Entry* left; Entry* right; switch(n->m_skew) { case SKEW_LEFT: n->m_skew = SKEW_NONE; return RES_OK; case SKEW_RIGHT: right = n->m_right; if(right->m_skew == SKEW_RIGHT) { n ->m_skew = SKEW_NONE; right->m_skew = SKEW_NONE; RotateLeft( n ); } else { left = right->m_left; switch(left->m_skew) { case SKEW_RIGHT: n ->m_skew = SKEW_LEFT; right->m_skew = SKEW_NONE; break; case SKEW_LEFT: n ->m_skew = SKEW_NONE; right->m_skew = SKEW_RIGHT; break; default: n ->m_skew = SKEW_NONE; right->m_skew = SKEW_NONE; } left->m_skew = SKEW_NONE; RotateRight( n->m_right ); RotateLeft ( n ); } return RES_OK; default: n->m_skew = SKEW_RIGHT; return RES_BALANCE; } }
void RedBlackTree::BalanceInsertion(Node* target) { Node* temp; target->black = false; while (target != root && target->parent->black == false) { if (target->parent == target->parent->parent->left) { //parent is a left child temp = target->parent->parent->right; if (!temp->black) { target->parent->black = true; temp->black = true; target->parent->parent->black = false; target = target->parent->parent; } else { if (target == target->parent->right) { target = target->parent; RotateLeft(target); } target->parent->black = true; target->parent->parent->black = false; RotateRight(target->parent->parent); } } else { //parent is a right child, mirror the if temp = target->parent->parent->left; if (!temp->black) { target->parent->black = true; temp->black = true; target->parent->parent->black = false; target = target->parent->parent; } else { if (target == target->parent->left) { target = target->parent; RotateRight(target); } target->parent->black = true; target->parent->parent->black = false; RotateLeft(target->parent->parent); } } } root->black = true; }
Node<Key, Val>* FixUp(Node<Key, Val>* h){ if (IsRED(h->right)){ h = RotateLeft(h); } if (IsRED(h->left) && IsRED(h->left->left)){ h = RotateRight(h); } if (IsRED(h->left) && IsRED(h->right)){ FlipColor(h); } return h; }
Node<T>* AVLTree<T>::aux_add(Node<T>* current, T val ) { if( current == nullptr ) return new Node<T>( val ); if( val < current->data ) current->left = aux_add( current->left, val ); else current->right = aux_add( current->right, val ); current->height = std::max( Height(current->left), Height(current->right) ) + 1; int balance = ( current == nullptr ) ? 0: ( Height(current->left) - Height(current->right) ) ; // Balance the Tree if (balance > 1 && val < current->left->data ) return RotateRight(current); if (balance < -1 && val > current->right->data ) return RotateLeft(current); if (balance > 1 && val > current->left->data ) { current->left = RotateLeft( current->left ); return RotateRight(current); } if (balance < -1 && val < current->right->data ) { current->right = RotateRight(current->right); return RotateLeft(current); } return current ; }
template<typename T, typename KEY> RBTNode<T, KEY> *RBTree<T, KEY>::put(RBTNode<T, KEY> *h, T Value, KEY Key) { if (h == NULL) { h = new RBTNode<T, KEY>(Value, Key, RED); return h; } if (h->key > Key) h->pLeft = put(h->pLeft, Value, Key); else if (h->key < Key) h->pRight = put(h->pRight, Value, Key); else h->value = Value; if (!isRed(h->pLeft) && isRed(h->pRight)) { h = RotateLeft(h); } if (isRed(h->pLeft) && isRed(h->pLeft->pLeft)) { h=RotateRight(h); } if (isRed(h->pLeft) && isRed(h->pRight)) { flipcolors(h); } return h; }
template<typename T, typename KEY> RBTNode<T, KEY> *RBTree<T, KEY>::deletemax(RBTNode<T, KEY> *h) { if (isRed(h->pLeft)) h = RotateRight(h); if (h->pRight == NULL) { // be careful here hasn't check if the h is empty. //std::cout << "Delete max " << h->key << std::endl; delete h; return NULL; } if (!isRed(h->pRight) && !isRed(h->pRight->pLeft)) h = MoveRedRight(h); h->pRight = deletemax(h->pRight); if (isRed(h->pRight)) h = RotateLeft(h); return h; }
void MyKeyboard(int thekey, int mouseX, int mouseY) { switch(thekey) { case GLUT_KEY_UP:InclineCameraAltitude();break; case GLUT_KEY_DOWN:DeclineCameraAltitude();break; case GLUT_KEY_RIGHT:InclineCameraAzimuth();break; case GLUT_KEY_LEFT:DeclineCameraAzimuth();break; case 'w':MoveForward();break; case 's':MoveBackward();break; case 'c':ElevateCannon();break; case 'z':DeclineCannon();break; case '1':RotateLeft();break; case '2':RotateRight();break; } }
void cBauul::Logic(float min, float max) { if (nextState) { Stop(); animation_frame = 0; nextState = false; int random = rand()%5; if (random == 0) actionstate = STATE_MOVE_FORWARD; else if (random == 1) actionstate = STATE_ROTATE_LEFT; else if (random == 2) actionstate = STATE_ROTATE_RIGHT; else actionstate = STATE_STANDBY; } switch(actionstate) { case STATE_STANDBY: Stop(); break; case STATE_MOVE_FORWARD: MoveForward(min,max); break; case STATE_ROTATE_LEFT: RotateLeft(); break; case STATE_ROTATE_RIGHT: RotateRight(); break; } }
template<typename T, typename KEY> RBTNode<T, KEY> *RBTree<T, KEY>::deleteone(RBTNode<T, KEY> *h, KEY Key) { // Delete a node. // However will be not sure Key exists in the tree. Check if the Key exists before deleting. if (Key < h->key) { if (!isRed(h->pLeft) && !isRed(h->pLeft->pLeft)) h = MoveRedLeft(h); h->pLeft = deleteone(h->pLeft, Key); } else{ if (isRed(h->pLeft)) h = RotateRight(h); if ((Key == h->key) && !(h->pRight) ) { //std::cout << "Delete one specified node: " << h->key << ", value: " << h->value << std::endl; delete h; return NULL; } if (!isRed(h->pRight) && !isRed(h->pRight->pLeft)) h = MoveRedRight(h); if (Key == h->key) { //std::cout << "To delete " << h->key << ", delete subtree's min node" << std::endl; RBTNode<T, KEY> *temp = getmin(h->pRight); h->value = temp->value; h->key = temp->key; h->pRight = deletemin(h->pRight); } else h->pRight = deleteone(h->pRight, Key); } if (isRed(h->pRight)) h = RotateLeft(h); return h; }
int InsertRoot( pNode * proot, Item D ) { #define root (*proot) if( !root ) { root = NewNode( D ); return 1; } else if( D < root->Data ) { if( InsertRoot( &(root->Left), D ) ) { RotateRight( &(root) ); return 1; } return 0; } else if( D > root->Data ) { if( InsertRoot( &(root->Right), D ) ) { RotateLeft( &(root) ); return 1; } return 0; } return 0; #undef root }
// // RightShrunk: helper function for Remove and FindHighest // // See LeftShrunk for details. // CLR_RT_AVLTree::Result CLR_RT_AVLTree::RightShrunk( Entry*& n ) { NATIVE_PROFILE_CLR_CORE(); Entry* left; Entry* right; switch(n->m_skew) { case SKEW_RIGHT: n->m_skew = SKEW_NONE; return RES_BALANCE; case SKEW_LEFT: left = n->m_left; if(left->m_skew == SKEW_LEFT) { n ->m_skew = SKEW_NONE; left->m_skew = SKEW_NONE; RotateRight( n ); return RES_BALANCE; } else if(left->m_skew == SKEW_NONE) { n ->m_skew = SKEW_LEFT; left->m_skew = SKEW_RIGHT; RotateRight( n ); return RES_OK; } else { right = left->m_right; switch(right->m_skew) { case SKEW_LEFT: n ->m_skew = SKEW_RIGHT; left->m_skew = SKEW_NONE; break; case SKEW_RIGHT: n ->m_skew = SKEW_NONE; left->m_skew = SKEW_LEFT; break; default: n ->m_skew = SKEW_NONE; left->m_skew = SKEW_NONE; } right->m_skew = SKEW_NONE; RotateLeft ( n->m_left ); RotateRight( n ); return RES_BALANCE; } default: n->m_skew = SKEW_LEFT; return RES_OK; } }
bool Viewer::Init(const std::string params) { m_dropTarget = new DropTarget(this); m_normalRect = wxToRect(GetRect()); Bind(wxEVT_CLOSE_WINDOW, [&](wxCloseEvent& evt) { PerformOnClose(); evt.Skip(); }); ViewportBuilder b; b.BuildViewport(m_viewPort, this, m_cfg); m_adjust = std::make_shared<Adjust>(this); m_adjust->OnChange.connect([this](int a, int b, int c) { AdjustChange(a, b, c); }); m_mouseMap.AddAction(MouseFullscreen, [this](Win::MouseEvent) { ToggleFullscreenMode(); }); m_mouseMap.AddAction(MouseToggleFullSizeDefaultZoom, [&](Win::MouseEvent) { ZoomToggleFullSizeDefaultZoom(); }); m_mouseMap.AddAction(MouseNextImage, [this](Win::MouseEvent) { ImageNext(1); }); m_mouseMap.AddAction(MousePrevImage, [this](Win::MouseEvent) { ImagePrev(1); }); m_mouseMap.AddAction(MouseZoomIn, [this](Win::MouseEvent) { ZoomIn(); }); m_mouseMap.AddAction(MouseZoomOut, [this](Win::MouseEvent) { ZoomOut(); }); m_mouseMap.AddAction(MouseContext, [this](Win::MouseEvent e) { ShowContextMenu(e); }); m_mouseMap.AddAction(MouseRotateLeft, [this](Win::MouseEvent) { RotateLeft(); }); m_mouseMap.AddAction(MouseRotateRight, [this](Win::MouseEvent) { RotateRight(); }); m_contextMenu.Construct(this); m_keys.Construct(this); m_keys.SetBindings(m_cfg.Keyboard); m_lang = Intl::OnLanguageChanged.connect([&]() { UpdateImageInformation(); }); m_cacher.SetCodecFactoryStore(m_codecs); UpdateViewportConfig(); // Apply some settings that can't be set automatically UpdateMemoryLimits(); m_cacher.MessageTarget(this); // TODO: FIXME: This is very wrong, should be set to something that isn't hardcoded. m_cacher.SetMaximumResolutionHint(Geom::SizeInt(25600, 25600)); m_folderMonitor.OnEvent.connect([this](IO::FileEvent e) { AddNotification(e); }); m_cacher.WrapAround(m_cfg.View.BrowseWrapAround); AlwaysOnTop(m_cfg.View.AlwaysOnTop); ZoomMode(m_cfg.View.DefaultZoomMode); if (m_cfg.View.Maximized) { m_doMaximize = true; } m_viewPort.Init(); m_statusBar = CreateStatusBar(7); int widths[] = { StatFieldZoomWidth, -1, StatFieldImageDimWidth, StatFieldPosWidth, StatFieldTimeWidth, StatFieldFileSizeWidth, StatFieldLastModified }; m_statusBar->SetStatusWidths(7, widths); m_statusBar->Show(m_cfg.View.ShowStatusBar); SetImageLocation(params); SetDropTarget(m_dropTarget); return true; }
void wxPageContainer::OnLeftUp(wxMouseEvent& event) { wxPageInfo pgInfo; int tabIdx; // forget the zone that was initially clicked m_nLeftClickZone = wxFNB_NOWHERE; int where = HitTest(event.GetPosition(), pgInfo, tabIdx); switch(where) { case wxFNB_LEFT_ARROW: { RotateLeft(); break; } case wxFNB_RIGHT_ARROW: { RotateRight(); break; } case wxFNB_X: { // Make sure that the button was pressed before if(m_nXButtonStatus != wxFNB_BTN_PRESSED) break; m_nXButtonStatus = wxFNB_BTN_HOVER; DeletePage((size_t)m_iActivePage); break; } case wxFNB_TAB_X: { // Make sure that the button was pressed before if(m_nTabXButtonStatus != wxFNB_BTN_PRESSED) break; m_nTabXButtonStatus = wxFNB_BTN_HOVER; DeletePage((size_t)m_iActivePage); break; } case wxFNB_DROP_DOWN_ARROW: { // Make sure that the button was pressed before if(m_nArrowDownButtonStatus != wxFNB_BTN_PRESSED) break; m_nArrowDownButtonStatus = wxFNB_BTN_NONE; // Refresh the button status wxFNBRendererPtr render = wxFNBRendererMgrST::Get()->GetRenderer( GetParent()->GetWindowStyleFlag() ); wxClientDC dc(this); render->DrawDropDownArrow(this, dc); PopupTabsMenu(); break; } } event.Skip(); }
void del_balance(struct node *nptr) { struct node *sib; while( nptr!=root ) { if( nptr == nptr->parent->lchild ) { sib = nptr->parent->rchild; if( sib->color == red )/* Case L_1 */ { sib->color = black; nptr->parent->color = red; RotateLeft(nptr->parent); sib = nptr->parent->rchild; /*new sibling*/ } if(sib->lchild->color==black && sib->rchild->color==black) { sib->color=red; if(nptr->parent->color == red )/*Case L_2a*/ { nptr->parent->color = black; return; } else nptr=nptr->parent; /* Case L_2b */ } else { if(sib->rchild->color==black) /*Case L_3a*/ { sib->lchild->color=black; sib->color=red; RotateRight(sib); sib = nptr->parent->rchild; } sib->color = nptr->parent->color; /*Case L_3b*/ nptr->parent->color = black; sib->rchild->color = black; RotateLeft(nptr->parent); return; } } else { sib = nptr->parent->lchild; if( sib->color == red )/* Case R_1 */ { sib->color =black; nptr->parent->color = red; RotateRight(nptr->parent); sib = nptr->parent->lchild; } if( sib->rchild->color==black && sib->lchild->color==black) { sib->color=red; if(nptr->parent->color == red )/*Case R_2a*/ { nptr->parent->color = black; return; } else nptr=nptr->parent; /*Case R_2b */ } else { if(sib->lchild->color==black) /*Case R_3a*/ { sib->rchild->color=black; sib->color=red; RotateLeft(sib); display(root,0); sib = nptr->parent->lchild; } sib->color = nptr->parent->color;/*case R_3b*/ nptr->parent->color = black; sib->lchild->color = black; RotateRight(nptr->parent); return; } } }/*End of while*/ }/*End of del_balance*/
bool OGLObjsCamera::HandleKeystroke( const unsigned char in_c, const bool in_bShift, const bool in_bCntrl ) { switch ( in_c ) { case 'r' : if ( in_bShift == TRUE ) SpinClockwise( s_dDeltaRot ); else SpinCounterClockwise( s_dDeltaRot ); break; case 'x': if ( in_bShift == TRUE ) PosXAxis( ); else NegXAxis( ); break; case 'y': if ( in_bShift == TRUE ) PosYAxis( ); else NegYAxis( ); break; case 'z': if ( in_bShift == TRUE ) PosZAxis( ); else NegZAxis( ); break; case '1': RotateSelf(0, ((in_bShift == TRUE) ? -1.0 : 1.0) * s_dDeltaRot); break; case '2': RotateSelf(1, ((in_bShift == TRUE) ? -1.0 : 1.0) * s_dDeltaRot); break; case '3': RotateSelf(2, ((in_bShift == TRUE) ? -1.0 : 1.0) * s_dDeltaRot); break; case FL_Home: // up arrow Reset(); break; case 'h': // up arrow case FL_Page_Up : if ( in_bShift == TRUE ) { PanIn( s_dDeltaTrans ); } else if ( in_bCntrl == TRUE ) { s_dDeltaTrans *= 2.0; } else { SpinClockwise( s_dDeltaRot ); } break; case 'l': // up arrow case FL_Page_Down : if ( in_bShift == TRUE ) { PanOut( s_dDeltaTrans ); } else if ( in_bCntrl == TRUE ) { s_dDeltaTrans *= 2.0; } else { SpinCounterClockwise( s_dDeltaRot ); } break; case 'i': // up arrow case FL_Up : if ( in_bShift == TRUE ) { PanUp( s_dDeltaTrans ); } else if ( in_bCntrl == TRUE ) { s_dDeltaTrans *= 2.0; } else { RotateUp( s_dDeltaRot ); } break; case 'm': // down arrow case FL_Down : if ( in_bShift == TRUE ) { PanDown( s_dDeltaTrans ); } else if ( in_bCntrl == TRUE ) { s_dDeltaTrans *= 0.5; } else { RotateDown( s_dDeltaRot ); } break; case 'j': // left arrow case FL_Left : if ( in_bShift == TRUE ) { PanLeft( s_dDeltaTrans ); } else if ( in_bCntrl == TRUE ) { s_dDeltaRot *= 0.5; } else { RotateLeft( s_dDeltaRot ); } break; case 'k': // right arrow case FL_Right : if ( in_bShift == TRUE ) { PanRight( s_dDeltaTrans ); } else if ( in_bCntrl == TRUE ) { s_dDeltaRot *= 2.0; } else { RotateRight( s_dDeltaRot ); } break; case 'p' : // zoom if ( in_bShift == TRUE ) { PanIn( s_dDeltaTrans ); } else if ( in_bCntrl == TRUE ) { s_dDeltaZoom *= 1.1; } else { SetZoom( s_dDeltaZoom * GetZoom() ); } break; case 'n' : if ( in_bShift == TRUE ) { PanOut( s_dDeltaZoom ); } else if ( in_bCntrl == TRUE ) { s_dDeltaZoom *= 0.9; } else { SetZoom( GetZoom() / s_dDeltaZoom ); } break; default: //TRACE("Unknown char %d\n", Key); return FALSE; } return TRUE; }
void RBTree<T>::RBRemoveFixUp(Node<T>* x, Node<T>* xparent, bool xisleftchild){ Node<T>* xsibling; while (x != root && x->is_black && x != NULL) { if (xisleftchild) { xsibling = xparent->right; // Red sibling to x if (!xsibling->is_black) { xsibling->is_black = true; xparent->is_black = false; // x's parent must have been black RotateLeft(xparent); xsibling = xparent->right; } if (xsibling->is_black && xparent->is_black) { xsibling->is_black = false; x = xparent; } else { if (xsibling->right->is_black) { xsibling->left->is_black = true; xsibling->is_black = true; RotateRight(xsibling); xsibling = xparent->right; } xsibling->is_black = xparent->is_black; xparent->is_black = true; xsibling->right->is_black = true; RotateLeft(xparent); x = root; } } // Symmetric to if else { xsibling = xparent->left; // Red sibling to x if (!xsibling->is_black) { xsibling->is_black = true; xparent->is_black = false; // x's parent must have been black RotateRight(xparent); xsibling = xparent->left; } if (xsibling->is_black && xparent->is_black) { xsibling->is_black = false; x = xparent; } else { if (xsibling->left->is_black) { xsibling->right->is_black = true; xsibling->is_black = true; RotateLeft(xsibling); xsibling = xparent->left; } xsibling->is_black = xparent->is_black; xparent->is_black = true; xsibling->left->is_black = true; RotateRight(xparent); x = root; } } } // end of while loop x->is_black = true; }