Práctica 5. Set y Map.
dictionary.h
Ir a la documentación de este archivo.
1 
8 #ifndef __DICTIONARY_H__
9 #define __DICTIONARY_H__
10 
11 #include <iostream>
12 #include <set>
13 #include <vector>
14 #include <string>
15 
16 using namespace std;
17 
25 class Dictionary {
26 private:
30  set <string> words;
31 public:
37  Dictionary();
38 
45  Dictionary(const Dictionary& othr);
46 
51  Dictionary (const string & file_name);
52 
53 
60  bool exists(const string &s) const;
61 
68  bool insert(const string &s);
69 
76  bool erase(const string &s);
77 
85  void clear();
86 
93  bool empty() const;
94 
99  unsigned int size() const;
100 
106  vector<string> wordsOfLength(int length) const;
107 
113  int getOcurrences(char c) const;
114 
120  void anade(const Dictionary &dic);
121 
128  friend istream& operator>>(istream &is, Dictionary &dic);
129 
136  friend ostream& operator<<(ostream &os, const Dictionary& dic);
137 
141  class iterator{
142  private:
143  set<string>::iterator it;
144  public:
145  iterator & operator++(){++it;return *this;}
146  iterator & operator--(){--it;return *this;}
147  bool operator==(const iterator &i) const{return it==i.it;}
148  bool operator!=(const iterator &i) const{return it!=i.it;}
149  const string& operator* (){return *it;}
150  friend class Dictionary;
151  };
152 
157  iterator begin() const {
158  iterator i;
159  i.it = words.begin();
160  return i;
161  }
162 
167  iterator end() const {
168  iterator i;
169  i.it = words.end();
170  return i;
171  }
172 
173 private:
174 
179  void LoadDictionary(const string &file_name);
180 };
181 
182 
190 int count_ocurrences(char c, const string& word, size_t pos = 0);
191 
192 #endif
Clase para iterar sobre el diccionario.
Definition: dictionary.h:141
TDA Dictionary.
Definition: dictionary.h:25
iterator begin() const
Devuelve un iterador al principio del diccionario.
Definition: dictionary.h:157
iterator end() const
Devuelve un iterador al final del diccionario.
Definition: dictionary.h:167
istream & operator>>(istream &is, Dictionary &dic)
Definition: dictionary.cpp:23
ostream & operator<<(ostream &os, const Dictionary &dic)
Definition: dictionary.cpp:16
int count_ocurrences(char c, const string &word, size_t pos=0)
Función que cuenta el número de ocurrencias de un carácter en una palabra.
Definition: dictionary.cpp:63