Advertisement
donlk

C++ vizsga-megoldás

Jun 23rd, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #ifndef SETSEQ_H
  2. #define SETSEQ_H
  3.  
  4.  
  5. template<typename C, typename T = char>
  6. class SetSequence{
  7.  
  8.     private:
  9.         C container;
  10.     public:
  11.         //bool operator==(const SetSequence& s);
  12.             typedef typename C::iterator iterator;
  13.             typedef typename C::const_iterator const_iterator;
  14.         typedef typename C::value_type value_type;
  15.  
  16.         void push_back(value_type const &t)
  17.     {
  18.         bool hasValue = false;
  19.                 for(iterator it = container.begin(); it != container.end(); it++)
  20.         {
  21.                     if( *it == t ){ hasValue = true; }
  22.                 }
  23.             if (!hasValue) { container.push_back(t); }
  24.         }
  25.  
  26.     void push_front(value_type const &t)
  27.     {
  28.         bool hasValue = false;
  29.                 for(iterator it = container.begin(); it != container.end(); it++)
  30.         {
  31.             if( *it == t ){ hasValue = true; }
  32.                 }
  33.             if (!hasValue) { container.push_front(t); }
  34.         }
  35.  
  36.         void set_union(SetSequence const &s){
  37.             for(const_iterator it = s.begin(); it != s.end(); it++){
  38.                 push_back( *it );
  39.             }
  40.         }
  41.  
  42.         unsigned int size() const{return container.size();}
  43.         const T back() const {return container.back();}
  44.         const T& front() const {return container.front();}
  45.  
  46.     iterator begin(){ return container.begin(); }
  47.         iterator end(){ return container.end(); }
  48.         const_iterator begin() const{ return container.begin(); }
  49.         const_iterator end() const{ return container.end();}
  50.  
  51.         void erase(T const &t)
  52.     {  
  53.             for(iterator it = container.begin(); it != container.end();){
  54.                 if(*it == t) { it = container.erase(it);}
  55.         else { it++; }
  56.             }
  57.    
  58.         }
  59.  
  60.         unsigned int count(T const &t)
  61.     {
  62.             unsigned int db = 0;
  63.             for(iterator it = container.begin(); it != container.end(); it++){
  64.                 if(*it == t){ ++db; }
  65.             }
  66.             return db;
  67.         }
  68.  
  69. };
  70.  
  71. /*
  72. template<typename C, typename T = char>
  73. bool operator==(const SetSequence<C, T>& s)
  74. {
  75.     return true;
  76. }*/
  77.  
  78.  
  79. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement