-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectoryTree.cpp
More file actions
81 lines (67 loc) · 1.68 KB
/
DirectoryTree.cpp
File metadata and controls
81 lines (67 loc) · 1.68 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
vector<string> input;
vector<string> temp;
vector<vector<string>> output;
//map<string, vector<string>> output;
class StringParse{
public:
StringParse(string s) : m_s(s),m_position(1) {};
string getNextString();
private:
string m_s;
int m_position;
};
string StringParse::getNextString()
{
if ( m_position == -1 )
return "";
for ( int i = m_position; i < m_s.size(); i++ ){
if ( m_s[i] == '/' ) {
m_position = i + 1;
return m_s.substr(m_position,i);
}
}
m_position = -1;
return "";
}
int find(string s) {
for( int i = 0; i < temp.size(); i++ )
if( temp[i] == s ) return i;
temp.push_back(s);
output.push_back(vector<string>());
return temp.size()-1;
}
void DirectoryTree()
{
//output.insert( pair<string,vector<string>>("ROOT", vector<string>()));
for ( int i = 0 ; i < input.size(); i ++ ){
StringParse s(input[i]);
string t = s.getNextString();
while ( t != "" ){
output[find(t)].push_back(t);
t = s.getNextString();
}
}
// output.push_back("ROOT");
}
int main()
{
input.push_back("/usr/lib/libc");
input.push_back("/usr/bin/find");
input.push_back("/home/schveiguy/bashrc");
input.push_back("/usr/bin/bash");
input.push_back("/usr/local/bin/ssh");
DirectoryTree();
return 0;
}