0

On geeks for geeks I saw a different way to create the Node for linked list.

struct Node{
   int data;
   Node* next;
   Node(int x){
      data = x;
      next = NULL;
   }
}

Can someone please explain me how that node is defined.

stephen_mugisha
  • 889
  • 1
  • 8
  • 18
asdf
  • 1
  • 3

1 Answers1

1
 struct Node {
     int data;
     Node *next;
     Node(int x) : data(x), next(NULL) {}
 };

This is just a way to define structure with constructor in C++

You can use them simply like this

Node *node = new Node(4);
Arjun Singh
  • 387
  • 3
  • 9