Script started on Thu Mar 22 02:25:58 2001 [tsaiwn@ccbsd3] ListSTK> g++ mymain7.cpp [tsaiwn@ccbsd3] ListSTK> ./a.out 53770880 [tsaiwn@ccbsd3] ListSTK> [tsaiwn@ccbsd3] ListSTK> cat -n mystk7.h 1 //mystk7.h --- CopyLeft by tsaiwn@csie.nctu.edu.tw 2 // --- implement a Stack using in C++ STL class library 3 #include 4 using namespace std; 5 template 6 class MyStack { 7 list x; 8 public: 9 void push(const T& y) { 10 x.push_front(y); 11 } 12 T top( ) { 13 return x.front( ); 14 } 15 void pop( ) { 16 x.pop_front( ); 17 } 18 bool empty( ) { return x.begin() == x.end(); } 19 }; [tsaiwn@ccbsd3] ListSTK> cat -n mymain7.cpp 1 // mymain7.cpp -- @CopyLeft by tsaiwn@csie.nctu.edu.tw 2 // g++ mymain7.cpp ; ./a.out 3 using namespace std; 4 #include "mystk7.h" 5 //注意以下是 1999之後的 C++ 新寫法, 舊法使用 6 #include 7 int main( ){ 8 MyStack x; // 注意這! 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@ccbsd3] ListSTK> [tsaiwn@ccbsd3] ListSTK> g++ mymain7.cpp [tsaiwn@ccbsd3] ListSTK> ./a.out 53770880 [tsaiwn@ccbsd3] ListSTK> exit exit Script done on Thu Mar 22 02:28:58 2001