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

📄 stack.h

📁 This rar contains code from every chapter of Wrox.Ivor.Hortons.Beginning.Visual.C.Plus.Plus.2008.Mar
💻 H
字号:
// A push-down stack to store Box objects
class CStack
{
private:
  // Defines items to store in the stack
  struct CItem
  {
    CBox* pBox;                        // Pointer to the object in this node
    CItem* pNext;                      // Pointer to next item in the stack or null

    // Constructor
    CItem(CBox* pB, CItem* pN): pBox(pB), pNext(pN){}
  };

  CItem* pTop;                         // Pointer to item that is at the top

public:
  // Push a Box object on to the stack
  void Push(CBox* pBox)
  {
    pTop = new CItem(pBox, pTop);      // Create new Item and make it the top
  }

  // Pop an  object off the stack
  CBox* Pop()
  {  
    if(pTop == 0)                      // If the stack is empty
      return 0;                        // return null

    CBox* pBox = pTop->pBox;           // Get box from item
    CItem* pTemp = pTop;               // Save address of the top Item
    pTop = pTop->pNext;                // Make next item the top 
    delete pTemp;                      // Delete old top Item from the heap
    return pBox;
  }
};

⌨️ 快捷键说明

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