服务器建设网站软件,网站 无限下拉,顺德网站制作案例效果,可以做全景的网站使用一个队列实现栈的基本功能#xff1a;push、pop、判断栈是否为空等#xff0c;实现的代码如下#xff1a; #includeiostream
#includequeue
#includectime//计算代码所需要的时间
using namespace std;class MyStack
{
public:queueint… 使用一个队列实现栈的基本功能push、pop、判断栈是否为空等实现的代码如下 #includeiostream
#includequeue
#includectime//计算代码所需要的时间
using namespace std;class MyStack
{
public:queueint que;//判断栈是否为空bool empty(){return que.empty();}//入栈void push(int x){que.push(x);}//出栈int pop(){int size que.size();size--;while (size--){que.push(que.front());que.pop();}int result que.front();que.pop();return result;}//得到栈顶元素int top(){return que.back();}
};int main()
{clock_t starttime, endtime;starttime clock();//计时开始MyStack mystack;for (int i 1; i 4; i){mystack.push(i);}cout 栈顶元素为 mystack.top() endl;endtime clock();//计时开始cout 运行时间为: (double)(endtime - starttime) / CLOCKS_PER_SEC s endl;system(pause);return 0;
}