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


C++ BinTree::CheckParent方法代码示例

本文整理汇总了C++中BinTree::CheckParent方法的典型用法代码示例。如果您正苦于以下问题:C++ BinTree::CheckParent方法的具体用法?C++ BinTree::CheckParent怎么用?C++ BinTree::CheckParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinTree的用法示例。


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

示例1: Run

void EFSM::Run() { // input event and change ActiveStates
    // process action()
    InorderIterator<int> it(_root);
    it.First();
	while (!it.IsDone()) {
        BinTree<int> *curr = it.Current();
        //cout << it.Current()->data << endl;//test for trace state
        switch(curr->data) {
        	case A:
		        if (Event2 && curr->CheckParent(1, G)) {
			        Action2();
    	    	}
                break;
        	case B:
		        if (Event1 && curr->CheckParent(1, G) && curr->CheckParent(2, C) && curr->CheckParent(3, E)) {
			        Action1();
    	    	}
	        	if (Event3 && curr->CheckParent(1, G)) {
		        	Action2();
	    	    }
                break;   
	        case D:
	    	    if (Event2 && curr->CheckParent(1, F) && curr->CheckParent(2, E)) {
		    	    Action1();
        		}

		    // Two same Event3 on the same state D need to be different
	    	    if (Event3 && curr->CheckParent(1, F) && curr->CheckParent(2, E)) { //curr->parent->stateId :meaning F include D
		    	    Action3();
        		}
	        	if (Event3 && curr->CheckParent(1, H)) {
		        	Action2();
    	    	}
                break;
        }
        it.Next();
    }

    // change to next states according event
    PreorderIterator<int> it1(_root);
    it1.First();
	while (!it1.IsDone()) {
        bool changeState = false;
        BinTree<int> *p;
        BinTree<int> *curr = it1.Current();
        cout << stateName[curr->data] << endl;
        switch(curr->data) {
        	case A:
		        if (Event2 && curr->CheckParent(1, G)) {
                    curr = curr->parent;
                    delete curr->left;
                    curr->left = CreateBinTree(B, curr);
                    changeState = true;
    	    	    break;
    	    	} 
	    	    break;
        	case B:
		        if (Event1 && curr->CheckParent(1, G) && curr->CheckParent(2, C) && curr->CheckParent(3, E)) {
                    curr = curr->parent;
                    curr = curr->parent;
                    curr = curr->parent;
                    delete curr->left;
                    curr->left = new BinTree<int>(F, curr);
                    p = curr->left;
					p->left = CreateBinTree(D, p);
                    changeState = true;
    	    	    break;
    	    	}
	        	if (Event3 && curr->CheckParent(1, G)) {
                    curr = curr->parent;
                    delete curr->left;
                    curr->left = CreateBinTree(A, curr);
                    changeState = true;
    	    	    break;
	    	    }
	    	    break;  
	        case D:
	    	    if (Event2 && curr->CheckParent(1, F) && curr->CheckParent(2, E)) {
                    curr = curr->parent;
                    curr = curr->parent;
                    delete curr->left;
                    curr->left = CreateBinTree(B, curr);
                    changeState = true;
    	    	    break;
        		}

		    // Two same Event3 on the same state D need to be different
	    	    if (Event3 && curr->CheckParent(1, F) && curr->CheckParent(2, E)) {
                    curr = curr->parent;
                    curr = curr->parent;
                    delete curr->left;
                    curr->left = CreateBinTree(C, curr);
                    changeState = true;
    	    	    break;
        		}
	        	if (Event3 && curr->CheckParent(1, H)) {
                    curr = curr->parent;
                    delete curr->left;
                    curr->left = CreateBinTree(B, curr);
                    changeState = true;
//.........这里部分代码省略.........
开发者ID:Jonathan2251,项目名称:ow,代码行数:101,代码来源:example1_efsm.cpp


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