Advertisement
nex036ara

Deck

Dec 11th, 2011
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1.  
  2. #ifndef DECK_DEF
  3. #define DECK_DEF
  4. #include "lista.hpp"
  5.  
  6. template<class T>
  7. class Deck;
  8.  
  9. template <class T>
  10. void prinResultDeck(const Deck<T>&);
  11.  
  12. template<class T>
  13. class Deck: private List<T>{
  14.     public:
  15.  
  16.         Deck(){};
  17.         virtual ~Deck(){}
  18.         int getDeckSize()const {return List<T>:: getSize();}
  19.        void addToDeck(int,const T&);
  20.        bool readFromDeck(int, T&)const;
  21.        bool removeFromDeck(int);
  22.        bool emptyDeck()const{return List<T>:: empty();}
  23.        friend void prinResultDeck<>(const Deck&);
  24.        void clearDeck() {List<T>:: clear();}
  25.  };
  26.      template<class T>
  27.      void Deck<T>:: addToDeck(int n,const T &value){
  28.          if(n==1)   List<T>::add(1,value);
  29.             else if(n==getDeckSize())
  30.                     List<T>:: add(getDeckSize()+1,value);
  31.      }
  32.  
  33.        template<class T>
  34.        bool Deck<T>:: readFromDeck(int n, T &value)const{
  35.            if(n==1) {List<T>:: read(1,value); return true;}
  36.         else
  37.             if(n==getDeckSize()) {
  38.             List<T>:: read(getDeckSize()+1, value); return true;
  39.             }
  40.            else
  41.                 return false;
  42.        }
  43.  
  44.        template<class T>
  45.        bool Deck<T>:: removeFromDeck(int n){
  46.         if(n==1) {List<T>:: remove(1); return true;}
  47.             else
  48.             if(n==getDeckSize()) {
  49.                 List<T>:: remove(getDeckSize()); return true;
  50.                }
  51.                 else
  52.                     return false;
  53.        }
  54.  
  55.        template<class T>
  56.        void prinResultDeck(const Deck<T> &ref){
  57.        cout<<"sizeofDeck: "<<ref.getDeckSize()<<endl;
  58.        cout<<"ElementofDeck: ";
  59.        T res;
  60.         for(int i=1; i<=ref.getDeckSize(); i++){
  61.             if(i>1) cout<<" ";
  62.             ref.read(i,res);
  63.             cout<<res;
  64.  
  65.        } cout<<""<<endl;
  66.        }
  67. #endif
  68.  
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement