-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c04341
commit 514a6c9
Showing
358 changed files
with
59,524 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Comp 15, HW4, AlphaTesting.cpp | ||
|
||
// Annamira O'Toole 10/24/16 | ||
|
||
#include "Alphabetizer.h" | ||
|
||
void testRun1(); | ||
void testRun2(); | ||
|
||
int main() | ||
{ | ||
|
||
return 1; | ||
|
||
} | ||
|
||
void testRun1(){ | ||
|
||
Alphabetizer A = Alphabetizer(); | ||
A.run(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Comp 15, HW4, AlphaTesting.cpp | ||
|
||
// Annamira O'Toole 10/24/16 | ||
|
||
#include "Alphabetizer.h" | ||
|
||
int main() | ||
{ | ||
|
||
return 1; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Comp 15, HW4, Alphabetizer.cpp | ||
|
||
// Annamira O'Toole 10/27/16 | ||
|
||
// implements Alphabetizer class, includes fstream | ||
|
||
#include <iostream> | ||
#include <stdexcept> | ||
#include <cstdio> | ||
#include <fstream> | ||
|
||
#include "Alphabetizer.h" | ||
#include "StringBST.h" | ||
|
||
using namespace std; | ||
|
||
Alphabetizer::Alphabetizer(){ | ||
|
||
} | ||
|
||
Alphabetizer::~Alphabetizer(){ | ||
|
||
} | ||
|
||
void Alphabetizer::run(){ | ||
|
||
string s; | ||
cin >> s; | ||
|
||
// sets order | ||
if (s == "f") | ||
order = FORWARDS; | ||
else if (s == "r") | ||
order = REVERSE; | ||
|
||
// read in strings | ||
runStream(cin); | ||
|
||
// print tree | ||
cout << "[ cin, " + s + " : "; | ||
if (order == FORWARDS) | ||
printForwards(); | ||
else if (order == REVERSE) | ||
printReverse(); | ||
|
||
cout << " ]"; | ||
|
||
} | ||
|
||
void Alphabetizer::run(string filename, string s){ | ||
|
||
// sets order | ||
if (s == "f") | ||
order = FORWARDS; | ||
else if (s == "r") | ||
order = REVERSE; | ||
|
||
// read in strings with ifstream code from hw3 | ||
std::ifstream input; | ||
input.open(filename.c_str()); | ||
if (not input.is_open()) { | ||
cerr << "Unable to read " << filename << endl; | ||
} else { | ||
runStream(input); | ||
input.close(); | ||
} | ||
|
||
// print tree | ||
cout << "[ " + filename + ", " + s + " : "; | ||
if (order == FORWARDS) | ||
printForwards(); | ||
else if (order == REVERSE) | ||
printReverse(); | ||
|
||
cout << " ]"; | ||
|
||
} | ||
|
||
// reads istream string by string and adds each one to String BST "tree" | ||
void Alphabetizer::runStream(istream &myStream){ | ||
while (! myStream.eof()) { | ||
try { | ||
string next; | ||
myStream >> next; | ||
if ((next != "") && (next != " ")) | ||
tree.add(next); | ||
} catch (...) { | ||
cout << "ERROR" << endl; | ||
} | ||
} | ||
} | ||
|
||
void Alphabetizer::printForwards(){ | ||
|
||
cout << tree.getMin(); | ||
tree.removeMin(); | ||
while (!tree.isEmpty()){ | ||
cout << ", " + tree.getMin(); | ||
tree.removeMin(); | ||
} | ||
|
||
} | ||
|
||
void Alphabetizer::printReverse(){ | ||
|
||
cout << tree.getMax(); | ||
tree.removeMax(); | ||
while (!tree.isEmpty()){ | ||
cout << ", " + tree.getMax(); | ||
tree.removeMax(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Comp 15, HW4, Alphabetizer.cpp | ||
|
||
// Annamira O'Toole 10/27/16 | ||
|
||
// implements Alphabetizer class, includes fstream | ||
|
||
#include <iostream> | ||
#include <stdexcept> | ||
#include <cstdio> | ||
#include <fstream> | ||
|
||
#include "Alphabetizer.h" | ||
#include "StringBST.h" | ||
|
||
using namespace std; | ||
|
||
Alphabetizer::Alphabetizer(){ | ||
|
||
} | ||
|
||
Alphabetizer::~Alphabetizer(){ | ||
|
||
} | ||
|
||
void Alphabetizer::run(){ | ||
|
||
string s; | ||
cin >> s; | ||
|
||
// sets order | ||
if (s == "f") | ||
order = FORWARDS; | ||
else if (s == "r") | ||
order = REVERSE; | ||
|
||
// read in strings | ||
runStream(cin); | ||
|
||
// print tree | ||
cout << "[ cin, " + s + " : "; | ||
if (order == FORWARDS) | ||
printForwards(); | ||
else if (order == REVERSE) | ||
printReverse(); | ||
|
||
cout << " ]"; | ||
|
||
} | ||
|
||
void Alphabetizer::run(string filename, string s){ | ||
|
||
// sets order | ||
if (s == "f") | ||
order = FORWARDS; | ||
else if (s == "r") | ||
order = REVERSE; | ||
|
||
// read in strings with ifstream code from hw3 | ||
std::ifstream input; | ||
input.open(filename.c_str()); | ||
if (not input.is_open()) { | ||
cerr << "Unable to read " << filename << endl; | ||
} else { | ||
runStream(input); | ||
input.close(); | ||
} | ||
|
||
// print tree | ||
cout << "[ " + filename + ", " + s + " : "; | ||
if (order == FORWARDS) | ||
printForwards(); | ||
else if (order == REVERSE) | ||
printReverse(); | ||
|
||
cout << " ]"; | ||
|
||
} | ||
|
||
// reads istream string by string and adds each one to String BST "tree" | ||
void Alphabetizer::runStream(istream &myStream){ | ||
while (! myStream.eof()) { | ||
try { | ||
string next; | ||
myStream >> next; | ||
tree.add(next); | ||
} catch (...) { | ||
cout << "ERROR" << endl; | ||
} | ||
} | ||
} | ||
|
||
void Alphabetizer::printForwards(){ | ||
|
||
cout << tree.getMin(); | ||
tree.removeMin(); | ||
while (!tree.isEmpty()){ | ||
cout << ", " + tree.getMin(); | ||
tree.removeMin(); | ||
} | ||
|
||
} | ||
|
||
void Alphabetizer::printReverse(){ | ||
|
||
cout << tree.getMax(); | ||
tree.removeMax(); | ||
while (!tree.isEmpty()){ | ||
cout <<", " + tree.getMax(); | ||
tree.removeMax(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Comp 15, HW4, Alphabetizer.h | ||
|
||
// Annamira O'Toole 10/27/16 | ||
|
||
// header file for Alphabetizer class, includes iostream and cstdio | ||
|
||
#ifndef ALPHABETIZER_H | ||
#define ALPHABETIZER_H | ||
|
||
#include "StringBST.h" | ||
#include <iostream> | ||
#include <stdexcept> | ||
#include <cstdio> | ||
|
||
using namespace std; | ||
|
||
class Alphabetizer { | ||
|
||
public: | ||
|
||
Alphabetizer(); | ||
~Alphabetizer(); | ||
|
||
void run(); // launches command line version of Alphabetizer | ||
void run(string filename, string order); // reads from files and prints to cout | ||
|
||
private: | ||
|
||
const int FORWARDS = 0; | ||
const int REVERSE = 1; | ||
StringBST tree; | ||
int order; | ||
|
||
void runStream(istream &myStream); // handles reading strings into the | ||
// StringBST "tree" | ||
|
||
void printForwards(); | ||
void printReverse(); | ||
|
||
}; | ||
|
||
#endif |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Comp 15, HW4, BSTTesting.cpp | ||
|
||
// Annamira O'Toole | ||
|
||
#include "StringBST.h" | ||
#include <iostream> | ||
using namespace std; | ||
|
||
void testPrint(); | ||
void testAdd(); | ||
void testRemoveRoot(); | ||
void testRemoveLeaf(); | ||
void testRemoveOneChild(); | ||
void testRemoveTwoChildren(); | ||
void testRemoveTreeSizeOne(); | ||
|
||
int main() | ||
{ | ||
|
||
testRemoveTwoChildren(); | ||
return 1; | ||
|
||
} | ||
|
||
void testPrint(){ | ||
string arr[] = {"B", "A", "C"}; | ||
StringBST T = StringBST(arr, 3); | ||
T.print(); | ||
} | ||
|
||
void testAdd(){ | ||
string arr[] = {"B", "A", "C"}; | ||
StringBST T = StringBST(arr, 3); | ||
|
||
T.add("B"); | ||
T.print(); | ||
cout << endl; | ||
|
||
} | ||
|
||
void testRemoveRoot(){ | ||
string arr[] = {"B", "A", "C"}; | ||
StringBST T = StringBST(arr, 3); | ||
T.print(); | ||
cout << endl; | ||
T.remove("B"); | ||
T.print(); | ||
cout << endl; | ||
} | ||
|
||
void testRemoveLeaf(){ | ||
string arr[] = {"B", "A", "C"}; | ||
StringBST T = StringBST(arr, 3); | ||
|
||
T.remove("A"); | ||
T.print(); | ||
cout << endl; | ||
} | ||
|
||
void testRemoveTwoChildren(){ | ||
string arr[] = {"D", "B", "A", "C", "F", "E", "G"}; | ||
StringBST T = StringBST(arr, 7); | ||
|
||
T.print(); | ||
cout << endl; | ||
T.remove("B"); | ||
T.print(); | ||
cout << endl; | ||
} | ||
|
||
void testRemoveOneChild(){ | ||
string arr[] = {"D", "B", "A", "C", "F", "E"}; | ||
StringBST T = StringBST(arr, 6); | ||
|
||
T.remove("F"); | ||
T.print(); | ||
cout << endl; | ||
} | ||
|
||
void testRemoveTreeSizeOne(){ | ||
string arr[] = {"A"}; | ||
StringBST T = StringBST(arr, 1); | ||
T.remove("A"); | ||
T.print(); | ||
} |
Oops, something went wrong.