标签:col empty amp i++ bool 入栈 style space als
一、
#include <iostream> using namespace std; class MyStack { private: char *m_pBuffer; //栈空间指针 int m_iSize; //栈容量 int m_iTop; //栈顶,栈中元素个数 public: MyStack(int Size)//传入栈的大小 { m_iSize = Size; m_pBuffer = new char[m_iSize]; m_iTop = 0; } ~MyStack() { delete []m_pBuffer; } bool stackEmpty()//判断栈是否为空 { if(m_iTop == 0)//if(0 == m_iTop) { return true; } return true; } bool stackFull()//判断栈是否已满 { if(m_iTop >= m_iSize) { return true; } return false; } void clearStack()//清空栈 { m_iTop = 0; } int stackLength()//返回栈的长度 { return m_iTop; } bool push(char elem)//将elem压入栈中 { if(stackFull()) { return false; } m_pBuffer[m_iTop] = elem; m_iTop++; return true; } bool pop(char &elem)//返回栈顶元素 { if(stackEmpty()) { return false; } m_iTop--; elem = m_pBuffer[m_iTop]; return true; } void stackTraverse( )//遍历栈 { for(int i=0;i<m_iTop;i++) { cout<<m_pBuffer[i]<<endl; } } }; int main() { cout << "Hello world!" << endl; return 0; }
标签:col empty amp i++ bool 入栈 style space als
原文地址:https://www.cnblogs.com/good-hair/p/11905927.html