⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soln7_7.cpp

📁 Wrox.Ivor.Hortons.Beginning.Visual.C.Plus.Plus.2008 With sourcecode
💻 CPP
字号:
// Soln7_7.cpp

#include <iostream>                   // For stream input/output

using std::cout;
using std::endl;

class CStack
{
public:
   CStack() : next(0) {}
   void push(int i);
   int pop();
   void print();
private:
   int list[100];
   int next;
};

// Push a value on to the stack
void CStack::push(int i)
{
   if (next < 99)
      list[next++] = i;
}

// Pop a value off the stack
int CStack::pop()
{
   return list[--next];
}

// Output the contents of the stack
void CStack::print()
{
   cout << '[';
   for(int i=next-1 ; i>=0 ; i--)
      cout << ' '<< list[i];
   cout << " ]\n";
}

int main()
{
   CStack s;

   s.print();

   s.push(5);
   s.push(10);
   s.push(8);

   s.print();

   cout << "top of stack=" << s.pop() << endl;

   s.print();

   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -