本文整理汇总了C++中MyStack::Peak方法的典型用法代码示例。如果您正苦于以下问题:C++ MyStack::Peak方法的具体用法?C++ MyStack::Peak怎么用?C++ MyStack::Peak使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyStack
的用法示例。
在下文中一共展示了MyStack::Peak方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}