本文整理汇总了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;
//.........这里部分代码省略.........