// Stack.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> using namespace std; enum{COUNT = 8}; typedef int TYPE; class CStack { TYPE m_pData[COUNT]; int m_nTop; int m_nCount; public: bool isFull() { return m_nTop+1>= m_nCount; } bool isEmpty() { return m_nTop < 0; } void push(const TYPE& data) { if (isFull()) { return; } m_pData[++m_nTop] = data; } bool pop(TYPE& t) { if (isEmpty()) { return false; } t = m_pData[m_nTop--]; return true; } CStack(); ~CStack(){} }; CStack::CStack() { m_nTop = -1; m_nCount = COUNT; } int _tmain(int argc, _TCHAR* argv[]) { CStack stack; int i = 0; while (i < 8) { stack.push(i++); } TYPE t; stack.pop(t); stack.pop(t); stack.pop(t); stack.pop(t); while (i<13) { stack.push(++i); } i = 0; while(stack.pop(t)) { cout << t << endl; } getchar(); return 0; }
时间: 2024-10-18 01:13:18