Skip to content
Snippets Groups Projects
Tree.cpp 1.25 KiB
Newer Older
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include "Tree.hpp"
#include "Node.hpp"
Paul Heinzlreiter's avatar
Paul Heinzlreiter committed
	using namespace std;

Paul Heinzlreiter's avatar
Paul Heinzlreiter committed
		//insert dummy root node
		this->nodes = new Node(this);
Paul Heinzlreiter's avatar
Paul Heinzlreiter committed
		delete this->nodes;
Paul Heinzlreiter's avatar
Paul Heinzlreiter committed
		//remove all nodes; refresh root node
Paul Heinzlreiter's avatar
Paul Heinzlreiter committed
		while (this->nodes->next != this->nodes) {
			Node* node = this->nodes->next;
Paul Heinzlreiter's avatar
Paul Heinzlreiter committed

			node->unlink();
			delete node;
Paul Heinzlreiter's avatar
Paul Heinzlreiter committed
		delete this->nodes;
		this->nodes = new Node(this);
Paul Heinzlreiter's avatar
Paul Heinzlreiter committed
	}

	bool Tree::isCorrect() {
		Node* current = this->nodes->next;
Paul Heinzlreiter's avatar
Paul Heinzlreiter committed

		while (current != this->nodes) {
			if (!current->isCorrect()) {
				return false;
			}
			current = current->next;
		}
		return true;
	unsigned long Tree::numberOfNodes() {
		unsigned long nodes = 0;

		for (Node* node = this->nodes->next; node != this->nodes; node = node->next) {
			nodes++;
		}
		return nodes;
	}

	vector<Body> Tree::dubinskiParse(string filename) {
		vector<Body> result;
		string line;
		ifstream infile(filename.c_str(), ifstream::in);
		double mass, px, py, pz, vx, vy, vz;

		while (infile >> mass >> px >> py >> pz >> vx >> vy >> vz) {
			Body b(px, py, pz, vx, vy, vz, mass);

			result.push_back(b);
		}
		infile.close();