Transferring.
This commit is contained in:
parent
46d724dd9d
commit
ea50b0cb6a
5 changed files with 99 additions and 0 deletions
BIN
hw2/hw2pr1/hw2pr1
Executable file
BIN
hw2/hw2pr1/hw2pr1
Executable file
Binary file not shown.
68
hw2/hw2pr1/hw2pr1.cpp
Normal file
68
hw2/hw2pr1/hw2pr1.cpp
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
// Name: Alexander Huddleston UIN: 223000555
|
||||||
|
// CSCE 420
|
||||||
|
// Due: 11:59 P.M. Monday, October 30, 2017
|
||||||
|
// hw2pr1.cpp
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <math.h>
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
node makeTree(string input, node n, int level)
|
||||||
|
{
|
||||||
|
char tempc = input[0];
|
||||||
|
input = input.substr(1);
|
||||||
|
|
||||||
|
if(tempc == '(')
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
while(input.length() != 0)
|
||||||
|
{
|
||||||
|
if(tempc)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// Initialization of input string.
|
||||||
|
string input = "";
|
||||||
|
|
||||||
|
// For testing, I want to read from a file.
|
||||||
|
// Typing in an tree from the keyboard each execution is a waste of time.
|
||||||
|
if(argc > 1)
|
||||||
|
{
|
||||||
|
if(!((string)argv[1]).substr(0, 2).compare("-f"))
|
||||||
|
{
|
||||||
|
ifstream file;
|
||||||
|
string line;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
file.open("hw2pr1_data.txt");
|
||||||
|
}
|
||||||
|
catch(exception e)
|
||||||
|
{
|
||||||
|
cerr << "File not found, or could not be opened." << endl;
|
||||||
|
}
|
||||||
|
while(!file.eof())
|
||||||
|
{
|
||||||
|
getline(file, line);
|
||||||
|
input += line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "Please input a tree: ";
|
||||||
|
cin >> input;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << input << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
1
hw2/hw2pr1/hw2pr1_data.txt
Normal file
1
hw2/hw2pr1/hw2pr1_data.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
((3,12,8),(2,4,6),(14,5,2))
|
5
hw2/hw2pr1/makefile
Normal file
5
hw2/hw2pr1/makefile
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
all: main.o
|
||||||
|
main.o: hw2pr1.cpp
|
||||||
|
g++ -std=c++17 hw2pr1.cpp -o hw2pr1
|
||||||
|
clean:
|
||||||
|
rm -rf *.o hw2pr1
|
25
hw2/hw2pr1/node.h
Normal file
25
hw2/hw2pr1/node.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef NODE_H
|
||||||
|
#define NODE_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class node
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
node* parent;
|
||||||
|
int level;
|
||||||
|
vector<node> children;
|
||||||
|
public:
|
||||||
|
void setParent(node* p) { parent = p; };
|
||||||
|
node* getParent() { return parent; };
|
||||||
|
void setLevel(int l) { level = l; };
|
||||||
|
int getLevel() { return level; };
|
||||||
|
void setChildren(vector<node> c) { children = c; };
|
||||||
|
void addChild(node n) { children.push_back(n); };
|
||||||
|
vector<node> getChildren() { return children; };
|
||||||
|
node getChildrenAt(int i) { return children.at(i); };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Reference in a new issue