Hello Word
I have a node struct as follows..
typedef struct Node
{
Node* left = nullptr;
Node* right = nullptr;
string word;
int lineNumber = 0;
int count = 0;
};
The goal here is to connect this node to other nodes ( I know very basic ) but I seem to be missing some subtleties that I may be overlooking
Here is my attempt
cout << "************Testing Root Node**********************\n" << endl;
1 Node *newNode = new Node;
2 Node temp = *newNode;
3 temp.word = word;
4 temp.lineNumber = lineNumber;
5 wtree.setRoot(newNode);
6 Node temp2 = *newNode;
7 cout << "Testing temp.word = " <<temp.word << endl;
8 cout << "Testing temp2.word = " << temp2.word << endl;
9 Node *test = wtree.getRoot();
10 Node test2 = *test;
cout << "RootNode.getWord() should be CATS it is...\n\n\ " << test2.word << endl;
cout << "************End of Root Node Test******************\n\n\n\n" << endl;
My Analysis
I believe that line 2 -4 are wrong but I just do not know how to fix it/
My output is this
Testing temp.word = cats
Testing temp2.word = _____(blank)
RootNode.getWord() should be CATS it is... _______ (blank)
This output tells me that the newNode is not being changed at all. So my temp.word = word is not doing the behavior I expect.
Can someone tell me how I should be handling this situation properly ? Thanks in advance
Please let me know if I have not been clear and I will gladly provide more details
I also tried
*newNode.word = word
But this gave me compile issues
Bonus question
Does the new operator do the same thing as malloc does ?
I am fairly new to C++ but I believe it does