tsaiwn@magpie % g++ mymain2.cpp mystk2.cpp -Wno-deprecated
tsaiwn@magpie % ./a.out
53770880
tsaiwn@magpie % cat -n mystk2.h
     1	//mystk2.h --- with mystk2.cpp --- by tsaiwn@csie.nctu.edu.tw
     2	//oOTgk: ŧigb mystk2.h o header file,
     3	//  @|{Xhg mystk2.cpp ,
     4	//L, ҤdFӨ empty( ) P isfull( ) b .h ɮפ,
     5	//]̬Ogb class , |۰ܦ inline function. 
     6	// (|vT½Ķ覡, |vT檺)
     7	//~, n`Nb mystk2.cpp n #include "mystk2.h"
     8	//ӥBϥΦ|D{ɮפ]n #include "mystk2.h"
     9	//
    10	class MyStack{
    11	   public:
    12	      enum{NELEMENT=99};
    13	   private:
    14	      int data[NELEMENT];
    15	      int stkptr;
    16	   public:
    17	      MyStack(void){ stkptr= -1; }
    18	      void push(int);
    19	      void pop(void);
    20	      int top(void);
    21	      int empty(void){ return (stkptr <= -1) ;}
    22	      int isfull(void){ return (stkptr >= NELEMENT-1);}
    23	};   // `NOѤF ";"
tsaiwn@magpie % cat -n mystk2.cpp
     1	// mystk2.cpp -- implementation of the stack (by tsaiwn@csie.nctu.edu.tw)
     2	#include "mystk2.h"
     3	void MyStack::push(int x)
     4	{
     5	    stkptr++;
     6	    data[stkptr] = x;
     7	}  
     8	int MyStack :: top(void)
     9	{
    10	    return data[stkptr];
    11	}
    12	//Actually,  pop( ) function is a void function in C++ STL
    13	void MyStack ::pop(void)
    14	{
    15	    if(stkptr> -1) --stkptr;
    16	}
tsaiwn@magpie % cat -n mymain2.cpp
     1	// mymain2.cpp  -- by tsaiwn@csie.nctu.edu.tw
     2	//  g++ mymain2.cpp  mystk2.cpp ; ./a.out
     3	#include "mystk2.h"
     4	//`NHU iostream.h ªgk; 1999᪺ C++ ϥ <iostream>
     5	// BnOog using namespace std;
     6	#include <iostream.h>
     7	int main( ) {
     8	   MyStack x;    // x is a Stack object
     9	   x.push(880);
    10	   x.push(770);
    11	   x.push(53);
    12	   while(!x.empty()){
    13	      cout << x.top();  x.pop();
    14	   }
    15	   cout << endl;
    16	}
tsaiwn@magpie % g++ mymain2.cpp mystk2.cpp -Wno-deprecated
tsaiwn@magpie % ./a.out
53770880
tsaiwn@magpie % exit
exit
