题1: 完成Stack类的改造,将其设置为模板类。 使用这个模板Stack类创建两个堆栈对象。 在主程序中创建一个字符堆栈,一个int堆栈,分别压入一个字符串和5个整数,从顶端分别打印出两个堆栈的内容。 【测试数据】 输入: hello 1 2 3 4 5 输出: o l l e h 5 4 3 2 1 说明: 输出行的末尾可以有一个空格 #include <iostream> #include<cstring> //stack的意思是堆,想象一堆堆在一起的文件,最上面的是top-1(就像数组一样的),最下面的是0(编号为0) using namespace std; const int MAX_SIZE=100; template <typename T>//typename可以把它替换成int之类的数据类型 //那么之后这个T就表示int数据类型 class Stack { private: T *data; //T类型数据的指针 int size; int top; public: /* 这里需要以下的函数 构造,析构,把元素弄出去的函数(需要判断是否为空),...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile