Question: ALL in C++ language 1. Display an Object Given the below definition for Node, we would like Node to be displayed as shown below. Write
ALL in C++ language
1. Display an Object
Given the below definition for Node, we would like Node to be displayed as shown below. Write the necessary operator to display a Node object. Assume the friend class is declared.
// Node N( 7 ); // cout << N << endl;
Outputs:
class Node {
public :
explicit Node( int Data) : Data {Data}, Next { nullptr }
{}
int Data ; Node * Next ;
};
2. Operator +
Write operator+ for the Node class such that when two Node objects are added, their Data is added together. The Next node pointer is ignored when adding.
3. Operator ==
Write the operator== for the Node class to check the equality of two Node objects such that: Two Nodes are equal, if they have the same memory address.
4. Loops
Write two versions of findNode that will look through a linked list of Node objects and return a Node pointer or nullptr . findNode may be called with a nullptr .
- Version1: Iterative version
- Version2: Recursive version
Node * findNode( Node * Start, int Value)
5. Templates
Rewrite the class definition of Node given below so that the Node can store any data type.
class Node {
public : explicit Node( int Data) : Data {Data}, Next { nullptr } {} int Data ; Node * Next ;
};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
