-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeTv.h
More file actions
186 lines (165 loc) · 5.55 KB
/
Copy pathTreeTv.h
File metadata and controls
186 lines (165 loc) · 5.55 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* Igor Lopes CS_121
April 13, 2015 Lab#11
*/
#include <iostream>
#include <string.h>
#include <fstream>
#include <stdio.h>
#include <cstring>
#include "BST.h"
using namespace std;
class TreeTv
{
public:
string* movie_titles;
string* movie_actors;
bool is_next_title;
int total_lines;
int total_titles;
string* tmp_data;
TreeTv()
{
total_lines = 0;
total_titles = 0;
SET_NUMBER_OF_LINES();
SET_DATA();
//SET_ACTORS();
}
public: void SET_NUMBER_OF_LINES()
{
ifstream readFile("tvDB.txt");
string line_data;
while (getline(readFile, line_data))
{
++total_lines;
}
}
public: void SET_DATA()
{
tmp_data = new string[total_lines];
ifstream readFile("tvDB.txt");
string line_data;
string curr_line;
int last_index = 0;
while (getline(readFile, line_data))
{
curr_line = line_data.c_str();
if(curr_line.empty())
{
tmp_data[last_index] = "VOID";
last_index++;
}
else
{
tmp_data[last_index] = curr_line;
last_index++;
}
}
SET_TOTAL_TITLES();
// SET_TITLES();
GET_ACTORS_TITLES();
}
public: void SET_TOTAL_TITLES()
{
bool isTitle = false;
string prev;
string curr = tmp_data[0];
for(int i = 1; i < total_lines; i++)
{
prev = curr;
curr = tmp_data[i];
if(prev == "VOID" && curr != "VOID" && isTitle == false)
{
isTitle = true;
}
if(isTitle == true)
{
++total_titles;
isTitle = false;
}
}
}
public: void SET_TITLES()
{
movie_titles = new string [total_titles];
int lastindex = 0;
ofstream File;
File.open ("titles.txt");
bool isTitle = false;
string prev;
string curr = tmp_data[0];
for(int i = 1; i < total_lines; i++)
{
prev = curr;
curr = tmp_data[i];
if(prev == "VOID" && curr != "VOID" && isTitle == false)
{
isTitle = true;
}
if(isTitle == true)
{
//string fitered = FILTER_TITLE(tmp_data[i]);
//File << fitered <<endl;
movie_titles[lastindex] = tmp_data[i];
lastindex++;
isTitle = false;
}
}
// BST tree (movie_titles, total_titles);
}
public: void GET_ACTORS_TITLES()
{
movie_titles = new string [total_titles];
movie_actors = new string [total_titles];
int last_index = 0;
int last_index_actors = 0;
int count = 0 ;
ofstream File;
File.open ("titles.txt");
bool isTitle = false;
string prev;
string curr = tmp_data[0];
string curr_title = " ";
string curr_actors = " ";
for(int i = 1; i < total_lines; i++)
{
prev = curr;
curr = tmp_data[i];
if(curr == "VOID")
{
// File << curr <<endl;
}
if(prev == "VOID" && curr != "VOID" && isTitle == false)
{
isTitle = true;
}
if(isTitle == false && count < 3)
{
count++;
}
if(isTitle == false && count == 3 && curr != "VOID")
{
string fitered = tmp_data[i];
curr_actors = curr_actors + "," + tmp_data[i];
//movie_actors[last_index] = curr_actors;
}
if(isTitle == true)
{
movie_titles[last_index] = tmp_data[i];
last_index++;
curr_title = tmp_data[i];
if( curr_actors != " ")
{
File << curr_actors <<endl;
movie_actors[last_index_actors] = curr_actors;
last_index_actors++;
}
curr_actors = "";
// File << curr_title <<endl;
isTitle = false;
count = 0;
}
}
BST tree (movie_titles,movie_actors, total_titles);
}
};