-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.cpp
30 lines (26 loc) · 864 Bytes
/
Node.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "Node.h"
#include <iostream>
using namespace std;
Node::Node() {
Coef = 1;
Exp = 1;
Next = nullptr;
}
Node::Node(double num1, int num2) {
Coef = num1;
Exp = num2;
}
std::ostream& operator<<(std::ostream& stream, const Node* nodeX){
if(nodeX != nullptr && nodeX->getCoef() != 0){ //check if node exists before anything
if (nodeX->getCoef() != 1 && nodeX->getExp() != 0)
stream << std::abs(nodeX->Coef);
//check if exponent isn't zero and isn't 1
if (nodeX->getExp() != 0 && nodeX->getExp() != 1)
stream << "x^" << nodeX->Exp;
else if (nodeX->getExp() == 1) //if exponent is 1 just input x into the stream
stream << "x";
if (nodeX->getExp() == 0 && nodeX->getCoef() != 0)
stream << std::abs(nodeX->getCoef());
}
return stream;
}