Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef DECK_DEF
- #define DECK_DEF
- #include "lista.hpp"
- template<class T>
- class Deck;
- template <class T>
- void prinResultDeck(const Deck<T>&);
- template<class T>
- class Deck: private List<T>{
- public:
- Deck(){};
- virtual ~Deck(){}
- int getDeckSize()const {return List<T>:: getSize();}
- void addToDeck(int,const T&);
- bool readFromDeck(int, T&)const;
- bool removeFromDeck(int);
- bool emptyDeck()const{return List<T>:: empty();}
- friend void prinResultDeck<>(const Deck&);
- void clearDeck() {List<T>:: clear();}
- };
- template<class T>
- void Deck<T>:: addToDeck(int n,const T &value){
- if(n==1) List<T>::add(1,value);
- else if(n==getDeckSize())
- List<T>:: add(getDeckSize()+1,value);
- }
- template<class T>
- bool Deck<T>:: readFromDeck(int n, T &value)const{
- if(n==1) {List<T>:: read(1,value); return true;}
- else
- if(n==getDeckSize()) {
- List<T>:: read(getDeckSize()+1, value); return true;
- }
- else
- return false;
- }
- template<class T>
- bool Deck<T>:: removeFromDeck(int n){
- if(n==1) {List<T>:: remove(1); return true;}
- else
- if(n==getDeckSize()) {
- List<T>:: remove(getDeckSize()); return true;
- }
- else
- return false;
- }
- template<class T>
- void prinResultDeck(const Deck<T> &ref){
- cout<<"sizeofDeck: "<<ref.getDeckSize()<<endl;
- cout<<"ElementofDeck: ";
- T res;
- for(int i=1; i<=ref.getDeckSize(); i++){
- if(i>1) cout<<" ";
- ref.read(i,res);
- cout<<res;
- } cout<<""<<endl;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement