zoukankan      html  css  js  c++  java
  • stack Virus

    typedef   int   stack_entry;    
      enum   Error_Code1{success1,overflow1,underflow1};    
      const   int   maxstack=10;  
      #include<iostream>  
      using   namespace   std;  
       
      class   stack  
      {  
            public:  
              stack();  
              bool   empty()const;  
              void   clear();  
              bool   full()const;  
              int   size()const;  
              Error_Code1   pop();  
              Error_Code1   top(stack_entry   &item)const;  
              Error_Code1   push(const   stack_entry   &item);  
              stack&   operator=(stack   &source);  
              friend   void   copy_stack(stack   &dest,stack   &source);  
      private:  
                      int   count;  
                      stack_entry     entry[maxstack];          
      };  
      stack   tstack;  
       
      stack&   stack::operator=(   stack   &source)  
      {  
               
            for   (int   i   =   0;   i<count;   i++)  
            {  
                  tstack.entry[i]   =   entry[i];  
                  tstack.count         =   count;  
            }  
            return   tstack;              
      }    
       
      void     copy_stack(stack   &dest,stack   &source)  
      {  
              dest.count   =   source.count;  
              for   (   int   i   =   0;   i<source.count;   i++)  
              {  
                      dest.entry[i]   =   source.entry[i];        
              }    
      }      
       
       
      Error_Code1   stack::push(const   stack_entry   &item)  
       
      {  
          Error_Code1   outcome   =   success1;  
          if(   count>maxstack)  
             
              outcome   =   overflow1;  
             
          else  
             
            entry[count++]   =   item;  
             
            return   outcome;          
       
      }  
       
      Error_Code1   stack::pop()  
      {  
              Error_Code1   outcome   =   success1;  
              if   (count   ==   0)  
                  outcome   =   underflow1;  
              else  
                  --count;  
                  return   outcome;  
      }  
       
      Error_Code1   stack::top(stack_entry   &item)const  
      {  
              Error_Code1   outcome=success1;  
              if   (count   ==   0)  
                 
                      outcome   =   underflow1;  
              else  
                     
                item   =   entry[count-1];  
               
              return   outcome;  
                   
      }  
       
      void   stack::clear()  
      {  
              count   =   0;  
              for   (int   i   =   0;   i<maxstack;   i++)  
                    {  
                            entry[i]   =   0;  
                    }          
      }  
       
       
      bool   stack::full()const  
      {        
      bool   outcome   =   true;  
              if   (count   ==   maxstack)  
                    outcome   =   false;  
              return   outcome;          
      }  
       
      int   stack::size()const  
      {  
              return   count-1;  
      }  
               
      bool   stack::empty()const  
      {  
              bool   outcome   =   true;  
              if   (count   ==   0)  
                    outcome   =   false;  
              return   outcome;  
                       
      }  
       
      stack::stack()  
      {  
              count   =   0;  
      }  
       
      int   main()  
      {  
               
              int   n;  
              stack   istack,teststack;  
              int   i;  
              int   item[maxstack];  
       
              cout<<"請輸入入棧整數個數(<10):"<<endl;  
              cin>>n;  
              for   (   i   =   0;   i<n;   i++   )  
                {  
                            cin>>item[i];  
                            istack.push(item[i]);  
                           
                }  
                cout<<endl<<endl;  
                 
                while   (istack.empty())  
                  {    
                          for   (int   j=0;j<n;j++)  
                          {  
                              Error_Code1   Errcode;  
                                Errcode   =   istack.top(item[j]);  
                              cout<<item[j]<<endl;  
                              istack.pop();  
                          }          
                  }  
                  system("pause");  
                  return   0;  
      }   
     

    【Blog】http://virusswb.cnblogs.com/

    【MSN】jorden008@hotmail.com

    【说明】转载请标明出处,谢谢

    反馈文章质量,你可以通过快速通道评论:

  • 相关阅读:
    Java在ACM中的应用
    acm->stl
    残缺棋盘--状压DP
    EOJ Monthly 2019.3 A
    【CF1141E】Superhero Battle
    AtCoder Grant Contest 10.F 博弈
    莫比乌斯反演总结
    P2257 YY的GCD
    BZOJ1011 莫比乌斯反演(基础题
    HDU1695 莫比乌斯反演
  • 原文地址:https://www.cnblogs.com/virusswb/p/1061278.html
Copyright © 2011-2022 走看看