因為總用vector,卻忘記了有stack,今天用到棧頂的值才想起來,說起來stack很方便,也很容易用,看下邊例子:
1 #include<stack> 2 #include<iostream> 3 using namesapce std; 4 5 int main(void) 6 { 7 stack<int> v; 8 v.push(0); 9 v.push(1); 10 cout<<v.size()<<endl; 11 cout<<v.top()<<endl; 12 cout<<v.empty()<<endl; 13 v.pop(); 14 cout<<v.top()<<endl; 15 16 }