From ba0cdb3e92c6b417eb5e47373ebfed2dff0340b0 Mon Sep 17 00:00:00 2001 From: wyy Date: Mon, 1 Jul 2013 23:42:03 +0800 Subject: [PATCH] add iterator and bak --- Trie.cpp | 17 +++++++++++++++-- Trie.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/Trie.cpp b/Trie.cpp index f5eaa9d..de26d24 100644 --- a/Trie.cpp +++ b/Trie.cpp @@ -2,6 +2,16 @@ namespace CppJieba { + Trie::iterator Trie::begin() + { + return Trie::iterator(_root); + } + + Trie::iterator Trie::end() + { + return Trie::iterator(NULL); + } + Trie::Trie() { _root = NULL; @@ -167,8 +177,11 @@ using namespace CppJieba; int main() { Trie trie; - //trie.init("test/dict.txt"); - trie.init("dict.txt"); + trie.init("test/dict.txt"); + cout<count<() const + { + return ptNode; + } + + bool operator==(const TrieNodeIterator& x) const + { + return ptNode == x.ptNode; + } + + bool operator!=(const TrieNodeIterator& x) const + { + return ptNode != x.ptNode; + } + }; + class Trie { private: TrieNode* _root; + public: + typedef TrieNodeIterator iterator; + public: + iterator begin(); + iterator end(); public: Trie(); ~Trie();