//#include <iostream.h>
#include <stack.h>
void main()
/* Pre: The user supplies an integer n and n decimal numbers.
Post:The numbers are printed in reverse order.
Uses:The STL class stack and its methods */
{
int n;
double item;
stack<double>numbers;//declares and intializes a stack of numbers.
cout<<"Type in an integer n followed by n decimal numbers."<<endl;
cout<<"The numbers will be printed in reverse order."<<endl;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>item;
numbers.push(item);
}
cout<<endl<<endl;
while(!numbers.empty())
{
cout<<numbers.top()<<" ";
numbers.pop();
}
cout<<endl;
}
上面是实现是利用模版库中的Stack<类型>变量名 来实现的,其中在他的类库中还有很多这样的操作,其中还有对
列表的操作,对各个类库中的文件操作必须加上响应的头文件例如本程序中就必须存在#include <stack.h>或者还
可以使用#include <stack>,第一种是以前老版本中使用的,后一种才是现在的版本中所使用的,就象#include <iostream.h>一样,是在C语言下使用的,而#include <iostream> using namespace std;才是真正的C++中所使用
但是,他们的功能都是基本相同的,没有什么区别....