#include<iostream>
using namespace std;
class node
{
public:
int data;
node* next;
node() //default constructor
{
data = 0;
next = NULL;
}
node(int value) //parameterize constructor
{
data = value;
next = NULL;
}
};
int main()
{
node* n = new node(); //no argument
cout<<n->data<<"->";
node* n1 = new node(1); //1 argument
cout<<n1->data<<"->";
node* n2 = new node(2);
cout<<n2->data;
cout<<endl;
cout<<endl;
return 0;
}
I want to make link list with different constructor.I am not understanding what should I do in constructor where I gave next = NULL.problem my next pointer is NULL everywhere.It’s not pointing any other block.
New contributor
Searching Confidence is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.