现在的位置: 首页 > 综合 > 正文

使用数组作为数据成员来实现栈

2014年01月06日 ⁄ 综合 ⁄ 共 650字 ⁄ 字号 评论关闭

 

  1. /* 
  2.  *使用数组作为数据成员来实现栈 
  3.  *倒序使用数组:插入时从末尾插入,弹出时从末尾弹出 
  4.  *Stack(  ) 构造函数 
  5.  *top( ) 获得栈顶的元素,但不删除 
  6.  *empty(  ) 判断是否为空 
  7.  *display(  ) 显示栈内的数据 
  8.  *push(  ) 入栈 
  9.  *pop(  ) 出栈 
  10.  */ 
  11. #ifndef ARRAY_STACK_H 
  12. #define ARRAY_STACK_H 
  13. #include <iostream> 
  14.  
  15. const int STACK_CAPACITY=1024; 
  16. typedet int elementType; 
  17.  
  18. class Stack 
  19. public
  20.     Stack(  ); 
  21.     bool empty(  ) const
  22.     void display( osteam & out ) const
  23.     elementType top(  ) const
  24.     void push( const elementType& value ); 
  25.     void pop(  ); 
  26.      
  27. private
  28.     elementType m_array[ STACK_CAPACITY ]; 
  29.     int m_size; 
  30.     int m_top;    //指向栈顶     
  31.      
  32. }; 
  33.  
  34. ostream& opeartor <<(ostream & out,Stack& sstack  ) ; 
  35.  
  36.  
  37. #endif 

抱歉!评论已关闭.