Stack

来源:互联网 发布:域名绑定时出现未解析 编辑:程序博客网 时间:2024/05/19 02:29
#include "stdafx.h"#include <iostream>using namespace std;class Stack{double *m_s;int m_size;int m_top;public:Stack(int size = 2){m_size = size;m_top = -1;m_s = new double[m_size];}Stack(const Stack &s){m_size = s.m_size;m_top = s.m_top;m_s = new double[m_size];memcpy(m_s, s.m_s, m_size * sizeof(double));}~Stack(){delete [] m_s;}void Push(double item){m_s[++m_top] = item;}double Pop(){return m_s[m_top--];}};int main(){Stack s;s.Push(555.5);s.Push(666.6);Stack s2 = s;cout << s2.Pop() << endl;cout << s2.Pop() << endl;}


0 0