本文整理汇总了C++中Stack::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Stack::Clear方法的具体用法?C++ Stack::Clear怎么用?C++ Stack::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack::Clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
void main(void)
{
Stack<int> stack;
stack.PushBack(1);
stack.PushBack(2);
stack.PushBack(3);
stack.PushBack(4);
stack.PushBack(5);
cout << "Stack size : " << stack.Size() << endl;
cout << "Top element : " << stack.Top() << endl;
stack.PopBack();
stack.PopBack();
cout << "Stack size : " << stack.Size() << endl;
stack.Show();
stack.Clear();
if ( stack.IsEmpty() )
{
cout << "Stack is empty" << endl;
}
else
{
cout << "Stack is not empty" << endl;
}
system("@pause");
}
示例2: MakeAIMove
void Othello::MakeAIMove()
{
int biggestGain = -4 * BOARD_SIZE * gameType; // Start with a really low value because after many moves, we could end up with biggestGain being negative
int currGain;
int depth;
COORD move;
Stack bestMoves;
switch (gameType)
{
case 1:
depth = 0; // Evaluate no move (play any valid move)
break;
case 2:
depth = 1; // Evaluate wins by this move only
break;
case 3:
depth = 2; // Evaluate wins by this move and the opponent's move
break;
case 4:
depth = 5; // Evaluate wins by this move, the opponent's move and your next move
break;
}
for (int row = 0; row < BOARD_SIZE; row ++) // Rows
{
for (int col = 0; col < BOARD_SIZE; col ++) // Columns
{
if (ValidMove(row, col)) // If move is valid
{
currGain = MoveValue(row, col, depth);
move.Y = row;
move.X = col;
if (currGain > biggestGain) // If we found a new best move
{
biggestGain = currGain;
bestMoves.Clear(); // Remove all the older moves, because this one is better
bestMoves.Push(move); // Add this move to the stack
}
else if (currGain == biggestGain) // If this move is as good as the best one
bestMoves.Push(move); // Add it to the stack
}
}
}
move = bestMoves.GetRandom();
MakeMove(move.Y, move.X);
}
示例3: main
int main(int arg, char* argv[])
{
Stack<int> S;
int x;
S.Push(1);
S.Push(2);
S.Push(3);
x = S.Top();
std::cout << x << std::endl;
S.Pop();
x = S.Top();
std::cout << x << std::endl;
S.Clear();
S.Push(3);
x = S.Top();
std::cout << x << std::endl;
S.~Stack();
std::cin.sync();
std::cin.get();
return 0;
}