⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack.h

📁 这是本人精心搜集的关于常用图论算法的一套源码
💻 H
字号:
#include<iostream.h>
enum Error_code{ success, overflow, underflow };
const int maxstack = 10; 
class Stack
 { public:
       Stack( );
       bool empty( )const;
       Error_code pop( );
       Error_code top(Stack_entry &item) const;
       Error_code push(const Stack_entry &item);
    private:
       int count;
       Stack_entry entry[maxstack];
};
Error_code Stack::push(const Stack_entry &item)
/* Pre: None.
    Post: If the Stack is not full,item is added to the top 
          of the Stack.If the Stack is full,an Error_code 
          of overflow is returned and the Stack is left unchanged.  */
{
  Error_code outcome=success;
  if(count >= maxstack) outcome= overflow;
    else entry[count++] = item;
  return outcome;
}
Error_code Stack::pop( )
/* Pre: None.
   Post: If the Stack is not empty, the top of the Stack 
         is removed.  If the Stack is empty, an 
         Error_code of underflow is returned and the 
         Stack is left unchanged.  */
{
   Error_code outcome=success;
   if(count == 0) outcome=underflow;
    else --count;
   return outcome;
}
Error_code Stack::top(Stack_entry &item) const
/* Pre: None.
    Post: If the Stack is not empty, the top of the Stack 
             is returned in item.If the Stack is empty, an 
             Error_code of underflow is returned and the 
             Stack is left unchanged.  */
{
   Error_code outcome = success;
   if(count == 0) outcome = underflow;
    else item = entry[count - 1];
   return outcome;
}
bool Stack::empty( )const
/* Pre: None.
   Post: If the Stack is empty, true is returned. 
         Otherwise false is returned. */
{
   bool outcome = true;
   if(count > 0) outcome = false;
   return outcome;
}
Stack::Stack() 
/* Pre: None.
   Post: The stack is initialized to be empty. */
{  count = 0 ;   }


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -