//stk4.cpp, CopyLeft by tsaiwn@csie.nctu.edu.tw // g++ stk4.cpp -Wno-deprecated ; ./a.out // 其實, C++ Class library 已經有 stack, //是以 template (樣板) 方式定義; 使用上更為方便! //但其函數名稱與用法與一般資料結構課本上講的稍有不同; //例如, 一般課本 pop不是void function. // 又如是否空堆疊用 empty( ) 不是 isempty( ) // 因為C++ 的一些資料結構class來自HP公司的 STL (Standard Template Library), //在更早時要 #include 才能使用 STL 裡面的 class. //後來, STL在1999年正式被納入 C++ 類別程式庫中, 可#include 各自的 header即可 // #include #include int main( ){ stack x; // STL 中的 stack 是 template x.push(880); x.push(770); x.push(53); while(!x.empty()){ cout << x.top(); x.pop(); } cout << endl; return 0; }