Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef ARERASE__H
- #define ARERASE__H
- #include <algorithm>
- #include <iostream>
- template <class T>
- class array_eraser {
- T* t;
- int sz;
- public:
- typedef T* iterator;
- array_eraser( T* arr, int s )
- {
- t = arr;
- sz = s;
- }
- void erase( const T& e )
- {
- int i = 0;
- while ( i < sz )
- {
- if ( t[ i ] == e ) { erase_index( i ); }
- else { i++; }
- }
- }
- void erase_index( int ind ) {
- T tmp = t[ ind ];
- for ( int i = ind; i < sz - 1; i++ )
- {
- t[ i ] = t [ i + 1 ];
- }
- sz--;
- t[ sz ] = tmp;
- }
- int size() const { return sz; }
- int count( const T& e ) const
- {
- return std::count( begin(), end(), e );
- }
- iterator begin() const {
- return t;
- }
- iterator end() const {
- return t + sz;
- }
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement