
Script started on Tue Mar 27 03:40:29 2007
[tsaiwn@ccbsd3]queue>   
[tsaiwn@ccbsd3]queue> cat -n myq7.h
    1 //myq7.h -- inplement a queue -- by tsaiwn@csie.nctu.edu.tw
    2 // Τ@ list (]tC, contains a list)
    3 #ifndef __MYQ7_H_
    4 #define __MYQ7_H_
    5 #include <list>
    6 using namespace std;
    7 template <class T>
    8  class MyStack {   // oO Queue, GNSW :-)
    9    list <T> x;
   10 public:
   11    void push(const T& y) {
   12       x.push_back(y);   // tail
   13    }
   14    T top( ) {
   15      return x.front( );  // head
   16    }
   17    void pop( ) {
   18       if(!empty( )) x.pop_front( );   // drop head
   19    }
   20    bool empty( ) { return x.begin() == x.end(); }
   21 };
   22 #endif

[tsaiwn@ccbsd3]queue> cat -n testmyq7.cpp
    1 // testmyq7.cpp -- by tsaiwn@csie.nctu.edu.tw
    2 //  g++ testmyq7.cpp  ; ./a.out
    3 #include "myq7.h"
    4 //`NHUO 1999᪺ C++ sgk, ªkϥ <iostream.h>
    5 #include<iostream>
    6 using namespace std;
    7 int main( ){
    8    MyStack <int> x;    // `No! O queue
    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]queue> g++ testmyq7.cpp
[tsaiwn@ccbsd3]queue> ./a.out
880 770 53 
[tsaiwn@ccbsd3]queue> exit
exit

Script done on Tue Mar 27 03:40:55 2007


D:\test> path C:\Dev-Cpp\bin;%path%

D:\test> g++ testmyq7.cpp

D:\test> a.exe
880 770 53 

D:\test>
