
使用类 模板 需要 模板 参数列表,请指教。。。
#include"stdafx.h"#include"iostream"#include"stack"usingnamespacestd;int_tmain(intarg...
#include "stdafx.h"
#include "iostream"
#include "stack"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int count=0;
int n;
cout<<"请输入一个数";
cin>>n;
stack fig=new stack();
int *a=new int[n];
a[0]=1;
a[1]=1;
for(int i=0;i<n;i++){
fig.push(a[n-1],fig);
}
for(int j=0;j<n;j++){
count=count+fig.top();
fig.pop(fig);}
return count;
} 展开
#include "iostream"
#include "stack"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int count=0;
int n;
cout<<"请输入一个数";
cin>>n;
stack fig=new stack();
int *a=new int[n];
a[0]=1;
a[1]=1;
for(int i=0;i<n;i++){
fig.push(a[n-1],fig);
}
for(int j=0;j<n;j++){
count=count+fig.top();
fig.pop(fig);}
return count;
} 展开
展开全部
这程序写的够乱的额。
一:std::stack是模板类,实现stack FILO功能
template< class T, class Container = std::deque<T> >
class stack{ ... }
使用时须指明参数,如std::stack<int>、std::stack<float>;
二:new/delete 动态内存的使用和释放
如std::stack<int>* fig = new std::stack<int>();
三:操作符号"."和"->"
通过对象访问用".",通过指针访问用“->"
写了点代码,供参考:
// 通过对象
stack<int> fig;
for( int i = 0; i < 10; i++ ){
fig.push( i );
}
while( !fig.empty() ){
cout<< fig.top() << endl;
fig.pop();
}
--
// 通过指针
stack<int>* fig=new stack<int>();
for( int i = 0; i < 10; i++ ){
fig->push( i );
}
while( !fig->empty() ){
cout<< fig->top() << endl;
fig->pop();
}
delete fig;

2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |