Stack.cpp: Defines the entry point of the console application. #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;}
The C + + algorithm writes itself a simple stack stack