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 <list>  in C++ STL class library
     3  #ifndef __MYSTK7_H_
     4  #define __MYSTK7_H_
     5  #include <list>
     6  using namespace std;
     7  template <class T>
     8  class MyStack {
     9     list <T> x;
    10  public:
    11     void push(const T& y) {
    12        x.push_front(y);
    13     }
    14     T top( ) {
    15       return x.front( );
    16     }
    17     void pop( ) {
    18       x.pop_front( );
    19     }
    20     bool empty( ) { return x.begin() == x.end(); }
    21  };
    22  #endif 
[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++ 新寫法, 舊法使用 <iostream.h>
     6  #include<iostream>
     7  int main( ){
     8     MyStack <int> 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<>/font
exit

Script done on Thu Mar 22 02:28:58 2001