-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
176 lines (146 loc) · 4.32 KB
/
Source.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
//Arno 40, Nick 35, Hiep 25
#include <iostream>
#include <fstream>
#include <string>
#include <stack>
#include <fstream>
#include "Node.h"
#include "List.h"
#include "ArgumentManager.h"
using namespace std;
int main(int argc, char** argv)
{
ArgumentManager am(argc, argv);
string inputFile = am.get("input");
string outputFile = am.get("output");
List Travis;
List Scarlet;
string passcode = "";
ifstream read(inputFile.c_str());
if (!read.is_open()) cout << "Input file did not open properly.\n";
else
{
string line;
while (line.empty())
{
getline(read, line);
}
//getline(read, line);
while (passcode == "")
{
if (line == "Scarlet") //we are working on Scarlet's linked list
{
while (line != "Travis" && line[0] != 'P')
{
getline(read, line);
if (line != "Travis" && line[0] != 'P')
Scarlet.adder(line);
}
}
if (line == "Travis") //we are working on Travis' linked list
{
while (line != "Scarlet" && line[0] != 'P')
{
getline(read, line);
if (line != "Scarlet" && line[0] != 'P')
Travis.adder(line);
}
}
else //we must be on the last line
{
passcode = line.substr(9, line.length() - 9);
/*
string garb;
getline(read, garb, ':');
read >> passcode;
*/
}
}
//make a linked list out of passcode
List Passcode;
for (int i = 0; i < passcode.length(); ++i)
{
if (isdigit(passcode[i]))
{
string num = "";
num += passcode[i];
Passcode.adder(num);
}
}
//print original
{
cout << "Original lists are as follows:\n";
cout << "Travis' original:\n";
for (Node* cur = Travis.getHead(); cur != nullptr; cur = cur->next)
cout << cur->evaluated << " ";
cout << endl;
cout << "Scarlet's original:\n";
for (Node* cur = Scarlet.getHead(); cur != nullptr; cur = cur->next)
cout << cur->evaluated << " ";
cout << endl;
}
//remove negatives and their corresponding positive values and reprint to check
Travis.removeNegs(Scarlet);
Scarlet.removeNegs(Travis);
{
cout << endl;
cout << "After remvoing negatives the lists are as follows:\n";
cout << "Travis':\n";
for (Node* cur = Travis.getHead(); cur != nullptr; cur = cur->next)
cout << cur->evaluated << " ";
cout << endl;
cout << "Scarlet's:\n";
for (Node* cur = Scarlet.getHead(); cur != nullptr; cur = cur->next)
cout << cur->evaluated << " ";
cout << endl;
}
//merge the two linked lists
List Combined;
//get all nodes from the host list
for (Node* cur = Travis.getHead(); cur != nullptr; cur = cur->next)
Combined.adder(cur->expression);
//get all nodes from the second list
for (Node* cur = Scarlet.getHead(); cur != nullptr; cur = cur->next)
Combined.adder(cur->expression);
Combined.setInvalidCount(Travis.getInvalidCount() + Scarlet.getInvalidCount());
{
cout << endl;
cout << "The combined list:\n";
for (Node* cur = Combined.getHead(); cur != nullptr; cur = cur->next)
cout << cur->evaluated << " ";
cout << endl;
}
//sort
Combined.bubbleSort();
{
cout << endl;
cout << "The sorted combined list:\n";
for (Node* cur = Combined.getHead(); cur != nullptr; cur = cur->next)
cout << cur->evaluated << " ";
cout << endl;
}
//remove the node a the position of invalid count
if (Combined.getInvalidCount() > 0)
Combined.removeByPos(Combined.getInvalidCount());
{
cout << endl;
cout << "We've removed the node at position invalidCount:\n";
for (Node* cur = Combined.getHead(); cur != nullptr; cur = cur->next)
cout << cur->evaluated << " ";
cout << endl;
}
ofstream write(outputFile.c_str());
if (!write.is_open()) cout << "Output file did not open properly.\n";
else
{
write << "Scarlet: ";
Scarlet.printLinkedList(write, Scarlet.getHead());
write << "Travis: ";
Travis.printLinkedList(write, Travis.getHead());
Combined.printTreasureCode(write, Combined.getHead());
Passcode.printActualCode(write, Passcode.getHead());
Combined.comparePasscode(write, passcode, Combined.getHead());
}
}
/////////////////////////////Do we need to actually verify that the passcode in Combined is equal to the passcode from input?
}