Untitled
unknown
plain_text
4 years ago
2.9 kB
7
Indexable
#include <iostream>
#include <ostream>
#include <string>
#include <fstream>
#include <sstream>
#include <exception>
#include "BinaryTree.h"
using namespace std;
int main(int argc, char **argv) {
// Checking for command line args
if (argc <= 1) {
cout << "Too few command line arguments..." << endl;
cout << "Format: ./Main file.txt" << endl;
exit(1);
} else if (argc > 2) {
cout << "More than one command line argument..." << endl;
cout << "Format: ./Main file.txt" << endl;
exit(1);
}
BinaryTree<int> intList;
BinaryTree<float> floatList;
BinaryTree<std::string> stringList;
string file = argv[1];
ifstream inputFile(file);
string userInput;
cout << "Enter tree type (i - int, f - float, s - std::string): ";
cin >> userInput;
bool input = true;
while (input) {
if (userInput.compare("i") == 0) {
int item;
while (inputFile >> item) {
intList.insert(item);
}
inputFile.close();
input = false;
} else if (userInput.compare("f") == 0) {
float item;
while (inputFile >> item) {
floatList.insert(item);
}
inputFile.close();
input = false;
} else if (userInput.compare("s") == 0) {
string item;
while (inputFile >> item) {
stringList.insert(item);
}
inputFile.close();
input = false;
} else {
cout << "Invalid list type" << endl;
cout << "Enter list type (i - int, f - float, s - std::string): ";
cin >> userInput;
}
} // While
// Main game loop
bool status = true;
string input2;
cout << "insert (i), delete (d), retrieve (r), length (l), in-order (n), pre-order (p),"
<< endl
<< "post-order (o), getNumSingleParent (s), getNumLeafNodes (f),"
<< endl
<< "getSumOfSubtrees (t), quit (q)"
<< endl;
while (status) {
cout << "Enter a command: ";
cin >> input2;
if (input2.compare("i") == 0) { // insert
} else if (input2.compare("d") == 0) { // delete
} else if (input2.compare("r") == 0) { // retrieve
} else if (input2.compare("l") == 0) { // length
} else if (input2.compare("n") == 0) { // in-order
} else if (input2.compare("p") == 0) { // pre-order
} else if (input2.compare("o") == 0) { // post-order
} else if (input2.compare("s") == 0) { // getNumSingleParent
} else if (input2.compare("f") == 0) { // getNumLeafNodes
} else if (input2.compare("t") == 0) { // getSumOfSubtrees
} else if (input2.compare("q") == 0) { // quit
}
}
}Editor is loading...