STL容器使用DEMO-stack
2009-08-24 16:33
344 查看
Code:
//////////////////////////////////////////////////////////////////////////
// CopyRight(c) 2009, YOYO, All Rights Reserved.
// Author: LIN YiQian
// Created: 2009/08/24
// Describe: STL stack 使用DEMO
//////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <stack>
using namespace std;
typedef stack<int> INT_STK;
void main(void)
{
INT_STK stkInt;
// Print is stack empty?
cout << "Stack Empty?: " << boolalpha << stkInt.empty() << endl;
// Push elements
for (int i = 0; i < 10; i += 2)
{
stkInt.push(i);
}
// Get size
cout << "Stack size: " << stkInt.size() << endl;
// Get top element & change its value
if (!stkInt.empty())
{
cout << "Top Element: " << stkInt.top() << " change to 99 " << endl;
stkInt.top() = 99;
}
// Print stack
{
while (!stkInt.empty())
{
cout << stkInt.top() << " ";
stkInt.pop();
}
}
cout << endl;
system("pause");
}
//////////////////////////////////////////////////////////////////////////
// CopyRight(c) 2009, YOYO, All Rights Reserved.
// Author: LIN YiQian
// Created: 2009/08/24
// Describe: STL stack 使用DEMO
//////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <stack>
using namespace std;
typedef stack<int> INT_STK;
void main(void)
{
INT_STK stkInt;
// Print is stack empty?
cout << "Stack Empty?: " << boolalpha << stkInt.empty() << endl;
// Push elements
for (int i = 0; i < 10; i += 2)
{
stkInt.push(i);
}
// Get size
cout << "Stack size: " << stkInt.size() << endl;
// Get top element & change its value
if (!stkInt.empty())
{
cout << "Top Element: " << stkInt.top() << " change to 99 " << endl;
stkInt.top() = 99;
}
// Print stack
{
while (!stkInt.empty())
{
cout << stkInt.top() << " ";
stkInt.pop();
}
}
cout << endl;
system("pause");
}
相关文章推荐
- 从零开始学C++之STL(十一):容器适配器(stack、 queue 、priority_queue)源码浅析与使用示例
- STL容器使用DEMO-multimap
- STL容器使用DEMO-set
- STL容器使用DEMO-priority_queue
- C++之STL(十一):容器适配器(stack、 queue 、priority_queue)源码浅析与使用示例
- C++ STL基本容器的使用(vector、list、deque、map、stack、queue)
- STL容器使用DEMO-multiset
- STL容器使用DEMO-valarray
- 从零开始学C++之STL(十一):容器适配器(stack、 queue 、priority_queue)源码浅析与使用示例
- STL容器使用DEMO-vector
- STL容器使用DEMO-queue
- STL容器使用DEMO-bitset
- STL容器使用DEMO-deque
- STL容器使用DEMO-list
- STL容器使用DEMO-map
- stl各个容器的使用时机
- C++ STL--stack/queue 的使用方法
- stl stack使用...
- 使用C++STL的map容器实现一种命令映射
- STL基础5:vector容器的使用总结