本文整理汇总了C++中MyStack::IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ MyStack::IsEmpty方法的具体用法?C++ MyStack::IsEmpty怎么用?C++ MyStack::IsEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyStack
的用法示例。
在下文中一共展示了MyStack::IsEmpty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PreTraverse
//先序
void MyTree::PreTraverse(TreeNode* pNode)
{
// if(pNode == NULL)
// {
// return;
// }
//
// printf("%d ", pNode->m_Data);
// PreTraverse(pNode->m_pLeft);
// PreTraverse(pNode->m_pRight);
MyStack<TreeNode*> ss;
TreeNode* pCur = pNode;
do
{
while(pCur)
{
printf("%d ", pCur->m_Data);
ss.push(pCur);
pCur = pCur->m_pLeft;
}
if(!ss.IsEmpty())
{
pCur = ss.pop();
pCur = pCur->m_pRight;
}
}while(pCur || !ss.IsEmpty());
}
示例2: MidTraverse
//中序
void MyTree::MidTraverse(TreeNode* pNode)
{
MyStack<TreeNode*> ss;
TreeNode* pCur = pNode;
do
{
while(pCur)
{
ss.push(pCur);
pCur = pCur->m_pLeft;
}
if(!ss.IsEmpty())
{
pCur = ss.pop();
printf("%d ", pCur->m_Data);
pCur = pCur->m_pRight;
}
}while(pCur || !ss.IsEmpty());
}
示例3: RemoveAll
void MyTree::RemoveAll()
{
MyStack ss;
TreeNode *pCurNode = m_pRoot;
TreeNode *pLastNode = NULL;
while (true)
{
while (pCurNode != NULL)
{
ss.push(pCurNode);
pCurNode = pCurNode->m_pLeft;
}
if (ss.IsEmpty())
{
break;
}
pCurNode = ss.pop();
if (pCurNode->m_pLeft == NULL && pCurNode->m_pRight == NULL)
{
pLastNode = pCurNode;
}
else if (pCurNode->m_pRight == NULL ||
pCurNode->m_pRight == pLastNode)
{
pLastNode = pCurNode;
Del(pCurNode);
pCurNode = NULL;
continue;
}
else
{
ss.push(pCurNode);
pCurNode = pCurNode->m_pRight;
continue;
}
TreeNode *pDelNode = pCurNode;
pCurNode = pCurNode->m_pRight;
Del(pDelNode);
}
}
示例4: InfectDeadToNeighborsNonRecursive
void InfectDeadToNeighborsNonRecursive(vector<vector<char>> &board, int x, int y)
{
int n = board.size();
if (n == 0)
return;
int m = board.at(0).size();
if (m == 0)
return;
StackElem elem = { 1, x, y };
stack->Push(elem);
while (!stack->IsEmpty())
{
x = stack->Peak().x;
y = stack->Peak().y;
switch (stack->Peak().step)
{
case 0:
stack->Pop(elem);
break;
case 1:
board.at(x).at(y) = 'D';
printf("Infect %d %d\n", x, y);
//infect left
stack->Peak().step = 2;
if (y - 1 >= 0 && board.at(x).at(y - 1) == 'O') //step1
{
elem.step = 1;
elem.x = x;
elem.y = y - 1;
stack->Push(elem);
}
break;
case 2:
//infect right
stack->Peak().step = 3;
if (y + 1 < m && board.at(x).at(y + 1) == 'O') //step2
{
elem.step = 1;
elem.x = x;
elem.y = y + 1;
stack->Push(elem);
}
break;
case 3:
//infect down
stack->Peak().step = 4;
if (x + 1 < n && board.at(x + 1).at(y) == 'O') //step3
{
elem.step = 1;
elem.x = x + 1;
elem.y = y;
stack->Push(elem);
}
break;
case 4:
//infect up
stack->Peak().step = 0;
if (x - 1 >= 0 && board.at(x - 1).at(y) == 'O') //step4
{
elem.step = 1;
elem.x = x - 1;
elem.y = y;
stack->Push(elem);
}
break;
default:
break;
}
}
return;
}