-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (67 loc) · 1.65 KB
/
main.cpp
File metadata and controls
74 lines (67 loc) · 1.65 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
#include "btree.h"
#include "ArgumentManager.h"
using namespace std;
bool checkDup(vector<int> num, int data)
{
for (int i = 0; i < num.size(); i++)
{
if (num[i] == data)
{
return true;
}
}
return false;
}
int main(int argc, char* argv[]) {
ArgumentManager am(argc, argv);
string in = am.get("input");
string out = am.get("output");
string cmd = am.get("command");
vector<int> num;
ifstream input(in);
ofstream output(out);
ifstream command(cmd);
string degree;
string temp; //temp string to read getline
getline(command, degree);
degree = degree.substr(degree.find("=") + 1);
BTree t(stoi(degree));
if (input.is_open())
{
while (getline(input, temp))
{
stringstream temp2(temp);
string data;
while (!temp2.eof())
{
temp2 >> data;
if (!checkDup(num, stoi(data)))
{
num.push_back(stoi(data));
}
}
}
}
for (int i = 0; i < num.size(); i++)
{
t.insert(num[i]);
}
output << "Height=" << t.getHeight() << endl;
while (getline(command, temp))
{
temp = temp.substr(temp.find(' ') + 1); //Level #
if (stoi(temp) > t.getHeight())
{
output << "EMPTY\n";
}
else
{
t.traverse(stoi(temp) - 1,output);
output << endl;
}
}
input.close();
output.close();
command.close();
return 0;
}