00001
00006 #ifndef _conjunto_h
00007 #define _conjunto_h
00008
00009 #include <vector.h>
00010 #include <cassert>
00011
00033 template<class T>
00034 class Conjunto {
00035 private:
00054 Vector<T> v;
00055 int nelementos;
00065 bool posicion_elemento(int& pos, T e) const;
00066 public:
00067 Conjunto(): nelementos(0) {}
00068
00069
00070
00079 bool insertar(T e);
00088 bool borrar(T e);
00095 bool pertenece(T e) const { int pos; return posicion_elemento(pos,f); }
00100 bool vacio() const { return nelementos==0; }
00105 int num_elementos() const { return nelementos; }
00106
00107
00118 class const_iterador {
00119 private:
00120 const T* puntero;
00121 const_iterador(const T* p): puntero(p) {}
00122 public:
00123 const_iterador(): puntero(0) {}
00124
00125
00126
00127 const T& operator*() const
00128 {assert(puntero!=0);return *puntero; }
00129 const_iterador& operator++()
00130 {assert(puntero!=0);puntero++;return*this;}
00131 const_iterador& operator--()
00132 {assert(puntero!=0);puntero--;return *this;}
00133 bool operator!=(const const_iterador& v) const
00134 {return puntero!=v.puntero; }
00135 bool operator==(const const_iterador& v) const
00136 {return puntero==v.puntero; }
00137 friend class Conjunto<T>;
00138 };
00147 typedef const_iterador iterador;
00148
00149
00150
00151 const_iterador begin() const {return const_iterador (&(v[0]));}
00152 const_iterador end() const {return const_iterador (&(v[nelementos-1])+1);}
00153 };
00154
00155 #include<conjunto.cpp>
00156
00157 #endif