Skip to content

Commit

Permalink
complete backup of code
Browse files Browse the repository at this point in the history
  • Loading branch information
annamiraotoole committed Aug 24, 2017
1 parent 0c04341 commit 514a6c9
Show file tree
Hide file tree
Showing 358 changed files with 59,524 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added hw4/AlphaTesting
Binary file not shown.
22 changes: 22 additions & 0 deletions hw4/AlphaTesting.cpp
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();

}
12 changes: 12 additions & 0 deletions hw4/AlphaTesting.cpp~
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;

}
113 changes: 113 additions & 0 deletions hw4/Alphabetizer.cpp
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();
}

}
112 changes: 112 additions & 0 deletions hw4/Alphabetizer.cpp~
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();
}

}
42 changes: 42 additions & 0 deletions hw4/Alphabetizer.h
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 added hw4/Alphabetizer.h~
Empty file.
Binary file added hw4/BSTTesting
Binary file not shown.
85 changes: 85 additions & 0 deletions hw4/BSTTesting.cpp
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();
}
Loading

0 comments on commit 514a6c9

Please sign in to comment.