//mystk2.h --- with mystk2.cpp --- by tsaiwn@csie.nctu.edu.tw //這是正確的寫法: 把宣告寫在 mystk2.h 這 header file, // 實作堆疊的程式碼則寫到 mystk2.cpp 中, //不過, 此例中仍留了兩個函數 empty( ) 與 isfull( ) 在 .h 檔案中, //因為它們是直接寫在 class 內, 會自動變成 inline function. // (會影響翻譯方式, 但不會影響執行的答案) //此外, 要注意不但在 mystk2.cpp 中要 #include "mystk2.h" //而且使用此堆疊的主程式之檔案也要 #include "mystk2.h" // class MyStack{ public: enum{NELEMENT=99}; private: int data[NELEMENT]; int stkptr; public: MyStack(void){ stkptr= -1; } void push(int); void pop(void); int top(void); int empty(void){ return (stkptr <= -1) ;} int isfull(void){ return (stkptr >= NELEMENT-1);} }; // 注意別忘了分號 ";"