-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.cpp
65 lines (58 loc) · 1.43 KB
/
tree.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "headers\\tree.h"
#include "headers\self.h"
using namespace std;
int branches(node *N)
{
if (N->_dir.size() == 0)
{
N->_fbranches = 1;
return N->_fbranches;
}
else
{
map<char, node *>::iterator it = N->_dir.begin();
while (it != N->_dir.end())
{
N->_fbranches += branches(it->second);
it++;
}
if (N->_fbranches > 1)
N->_str = L"";
return N->_fbranches;
}
}
node *map_create(map<string, wstring> iolist)
{
node *N0 = new node();
map<string, wstring>::iterator itr = iolist.begin();
while (itr != iolist.end())
{
string key = itr->first;
wstring val = itr->second;
node *latest_node = N0;
for (int i = 0; i < key.length(); i++)
{
if (latest_node->_dir[key[i]] == NULL)
{
latest_node->_dir[key[i]] = new node();
latest_node->_dir[key[i]]->_char = key[i];
latest_node->_dir[key[i]]->_depth = i + 1;
latest_node = latest_node->_dir[key[i]];
}
else
{
latest_node = latest_node->_dir[key[i]];
}
latest_node->_str = val;
}
itr++;
}
branches(N0);
return N0;
}
// int main()
// {
// map<string, wstring> iolist = iostrings();
// node* N0 = map_create(iolist);
// return 0;
// }