This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DvcSchedule7b.cpp
179 lines (158 loc) · 3.8 KB
/
DvcSchedule7b.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
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
// Lab 7b, Applying Advanced Linked-List Techniques
// Programmer: Minos Park
// Editor(s) used: Sublime Text 2
// Compiler(s) used: G++
#include <iostream>
#include <fstream>
#include <vector>
#include <cassert>
#include <string>
#include <ctime>
using namespace std;
struct SubjectCode
{
int sectionCount;
string section;
string term;
string name;
};
struct Node
{
SubjectCode data;
Node* next;
};
int main()
{
// print my name and this assignment's title
cout << "Lab 7b, Applying Advanced Linked-List Techniques\n";
cout << "Programmer: Minos Park\n";
cout << "Editor(s) used: Sublime Text 2\n";
cout << "Compiler(s) used: G++\n";
cout << "File: " << __FILE__ << endl;
cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
//vector<SubjectCode> subjectCodes;
Node* root = NULL;
Node* step = NULL;
Node* last = NULL;
Node* temp = NULL;
SubjectCode tmp;
vector<string> dup(1, "");
char *token;
char buf[1000];
string line;
const char* const tab = "\t";
int progressbar = 0;
int courseCount = 0;
bool check = false;
ifstream fin;
clock_t startTime = clock();
fin.open("dvc-schedule.txt");
if (!fin.good()) throw "I/O error";
getline(fin, line); //Eliminate first line
cout << "Progress Bar";
root = new Node;
step = root;
step->next = NULL;
root->data.sectionCount = 0;
tmp.sectionCount = 1;
while(fin.good())
{
if(progressbar % 1000 == 0)
{
cout << ".";
cout.flush();
}
progressbar++;
check = false;
getline(fin, line);
strcpy(buf, line.c_str());
if(buf[0] == 0) continue;
const string term(token = strtok(buf, tab));
const string section(token = strtok(0, tab));
const string course((token = strtok(0, tab))?token : "");
const string courseName(course.begin(), course.begin() + course.find('-'));
tmp.name = courseName;
tmp.section = section;
tmp.term = term;
for(int i = 0; i < dup.size(); i++)
{
if((dup[i].compare(0, term.size(), term)) == 0)
{
if((dup[i].find(',' + section, 12)) != -1 )
{
root->data.sectionCount++;
check = true;
}
else
{
dup[i] += ',' + section;
}
break;
}
if(i + 1 == dup.size())
dup.push_back((string) term + ',' + section);
}
if(check == false)
{
step = root->next;
while (step != NULL)
{
if (step->data.name.compare(tmp.name) == 0)
{
step->data.sectionCount ++;
check = true;
step = last;
break;
}
step = step->next;
}
}
if(check == false)
{
step = root->next;
last = root;
while (step != NULL)
{
if (step->data.name.compare(tmp.name) > 0)
{
temp = last->next;
last->next = new Node;
step = last->next;
step->next = temp;
break;
}
last = step;
step = step->next;
}
if(step == NULL)
{
last->next = new Node;
step = last->next;
step->next = NULL;
}
courseCount++;
assert(courseCount < 200);
step->data = tmp;
}
}
cout << endl << endl;
fin.close();
cout << "Total " << courseCount << " classes" << endl << endl;
step = root->next;
while (step != NULL)
{
cout << step->data.name << ", " << step->data.sectionCount << " classes" << endl;
step = step->next;
}
cout << endl;
cout << "Duplicates: " << root->data.sectionCount << endl << endl;
double elapsedSeconds = (double)(clock() - startTime) / CLOCKS_PER_SEC;
cout << "Computation Time: " << elapsedSeconds << endl;
step = root;
while (step != NULL)
{
last = step->next;
delete step;
step = last;
}
}