Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0622c1b

Browse files
committedJan 16, 2019
pair stack final
1 parent 6d5c974 commit 0622c1b

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed
 

‎Trie.h

+26-9
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,29 @@ template<class T, class E = char> class Trie {
215215
return this->stackyTheLittleStack == rhs.stackyTheLittleStack;
216216
};
217217

218+
// TrieIterator& operator ++() {
219+
// while(stackyTheLittleStack.top().first++ == stackyTheLittleStack.top().second){
220+
// stackyTheLittleStack.pop();
221+
// }
222+
// viewTrie + '\n' + addSpace(stackyTheLittleStack.size()) + stackyTheLittleStack.top().first++->first;
223+
// slideLeft(static_cast<InternalNode*>(stackyTheLittleStack.top().first++->second));
224+
// return *this;
225+
// };
218226
TrieIterator& operator ++() {
219-
while(stackyTheLittleStack.top().first++ == stackyTheLittleStack.top().second){
220-
stackyTheLittleStack.pop();
221-
}
222-
viewTrie + '\n' + addSpace(stackyTheLittleStack.size()) + stackyTheLittleStack.top().first++->first;
223-
slideLeft(static_cast<InternalNode*>(stackyTheLittleStack.top().first++->second));
224-
return *this;
225-
};
227+
popStack();
228+
viewTrie += '\n' + addSpace(stackyTheLittleStack.size()) += stackyTheLittleStack.top().first->first;
229+
slideLeft(static_cast<InternalNode*>(stackyTheLittleStack.top().first->second));
230+
return *this;
231+
};
232+
233+
void popStack() {
234+
typename mappy::iterator topIter = ++(stackyTheLittleStack.top().first);
235+
typename mappy::iterator topEnd = (stackyTheLittleStack.top().second);
236+
if (topIter == topEnd) {
237+
stackyTheLittleStack.pop();
238+
popStack();
239+
}
240+
}
226241

227242
std::string addSpace(int stackSize){
228243
std::string result = "";
@@ -263,7 +278,7 @@ template<class T, class E = char> class Trie {
263278
* Insert a single InternalNode or Leaf.
264279
*/
265280
iterator insert(const value_type& value) {
266-
key_type a = value.first;
281+
key_type a = value.first + '#';
267282
T b = value.second;
268283
root->insert(a,b);
269284
//return find(a);
@@ -294,8 +309,10 @@ template<class T, class E = char> class Trie {
294309

295310
void showTrie() {
296311
iterator cd = begin();
297-
while(cd != end()) {
312+
iterator ed = cd;
313+
while(cd != end() && ++ed != end()) {
298314
++cd;
315+
ed=cd;
299316
}
300317
std::cout << cd.viewTrie << std::endl;
301318
cd.viewTrie = "";

‎main.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,24 @@ Trie<string> baum;
2222
* Main Method to work with the Trie.
2323
*/
2424
int main() {
25-
baum.insert(pair<const basic_string<char>,string> ("test#","#test#"));
26-
baum.insert(pair<const basic_string<char>,string> ("klaus#","#klaus#"));
27-
baum.insert(pair<const basic_string<char>,string> ("fack#","#fack#"));
28-
baum.insert(pair<const basic_string<char>,string> ("fuck#","#fuck#"));
29-
cout << baum.begin().operator *();
25+
baum.insert(pair<const basic_string<char>,string> ("a","Meaning:a"));
26+
baum.insert(pair<const basic_string<char>,string> ("b","Meaning:b"));
27+
baum.insert(pair<const basic_string<char>,string> ("c","Meaning:c"));
28+
baum.insert(pair<const basic_string<char>,string> ("d","Meaning:d"));
29+
cout << baum.root->mappyTheLittleMap.size()<< endl;
3030

31+
//
32+
// for (auto it=baum.root->mappyTheLittleMap.begin(); it!=baum.root->mappyTheLittleMap.end(); ++it){
33+
// std::cout << it->first << std::endl;
34+
// }
3135

36+
37+
38+
cout << "a"<< baum.begin().operator *() << endl;
39+
cout << "b"<< baum.begin().operator ++().operator *()<< endl;
40+
cout << "c"<< baum.begin().operator ++().operator ++().operator *()<< endl;
41+
cout << "d"<< baum.begin().operator ++().operator ++().operator ++().operator *()<< endl;
42+
43+
baum.showTrie();
3244
}
3345

0 commit comments

Comments
 (0)
Please sign in to comment.