C\C++编程中:相对路径+绝对路径
1 template <typename T> 2 struct Stack{//自建栈 3 T *item; 4 int capacity; 5 int top; 6 Stack(int c = 1000) 7 { 8 capacity = c; 9 item = new T[capacity]; 10 top =0; 11 } 12 ~Stack(){ 13 capacity = 0; 14 top = 0; 15 delete [] item; 16 } 17 void push(const T &e) 18 { 19 if(top == capacity) 20 { 21 cout<<"栈满,栈溢出!"<<endl; 22 } 23 else{ 24 item[top++] = e; 25 } 26 } 27 T& pop() 28 { 29 if(top==0){ 30 cout<<"栈空"<<endl; 31 } 32 else{ 33 return item[--top]; 34 } 35 } 36 T& Top() 37 { 38 return item[top-1]; 39 } 40 bool Empty() 41 { 42 if(top==0)return true; 43 return false; 44 } 45 };
本文来自博客园,作者:键盘侠牧师,转载请注明原文链接:https://www.cnblogs.com/wangzhe52xia/p/12599680.html
浙公网安备 33010602011771号