Skip to content

Commit

Permalink
TrieIterator: Add iterator class
Browse files Browse the repository at this point in the history
  • Loading branch information
akshitgrover committed May 2, 2019
1 parent 8eb4621 commit 9c8d68c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions _trie_iterator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <string>
#include <iterator>

#include "_trie_node.h"

template <typename T>
class trie_iterator {
private:
tnode<T>* root;
public:
using iterator_category = std::bidirectional_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = std::pair<std::string, T>;
using pointer = value_type*;
using reference = value_type&;

// Constructors
explicit trie_iterator(tnode<T>*);
};

template <typename T>
trie_iterator<T>::trie_iterator(tnode<T>* root) {
this->root = root;
}
4 changes: 3 additions & 1 deletion trie.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <string>

#include "_trie_node.h"
#include "_trie_iterator.h"

template <typename T>
class trie {
public:
using iterator = trie_iterator<T>;

trie();
void insert(std::string, T);
bool exist(std::string);
Expand Down

0 comments on commit 9c8d68c

Please sign in to comment.