栈的数组实现

2014-11-23 21:38:25 · 作者: · 浏览: 2
 
/* 
 * stack_1.cpp 
 * 
 *  Created on: 2013年8月2日 
 *      Author: 黄东东 
 *      为能有章泽天这样的女朋友而不断努力......... 
 */  
  
  
#include    
  
using namespace std;  
  
typedef int T;  
class Stack{  
    T a[5];  
    int cur;  
  
public:  
    Stack():cur(0){  
  
    }  
    void push(const T& d ){  
        a[cur++] = d;  
    }  
  
    T pop(){  
  
        return a[--cur];  
    }  
  
    const T & top(){  
  
        return a[cur - 1];  
    }  
  
  
    bool empty(){  
  
        return cur == 0;  
    }  
  
    bool full(){  
  
        return cur == 5;  
    }  
  
    int size(){  
  
        return cur;  
    }  
  
    void clear(){  
  
        cur = 0;  
    }  
};  
  
  
int main(){  
  
    Stack s;  
  
    s.push(6);  
    s.push(7);  
    s.push(8);  
    s.push(9);  
    s.push(10);  
  
  
    while(!s.empty()){  
        cout<
using namespace std; typedef int T; class Stack{ T a[5]; int cur; public: Stack():cur(0){ } void push(const T& d ){ a[cur++] = d; } T pop(){ return a[--cur]; } const T & top(){ return a[cur - 1]; } bool empty(){ return cur == 0; } bool full(){ return cur == 5; } int size(){ return cur; } void clear(){ cur = 0; } }; int main(){ Stack s; s.push(6); s.push(7); s.push(8); s.push(9); s.push(10); while(!s.empty()){ cout<