In Data structure ad algorithm There are various linked list operations that allow us to perform different actions on linked lists includes the insertion operation which adds a new element to the linked list.
this example here demonstrates the implementation of linked list operation in C programming language , however the same logic / idea can also be implemented in C ++ ,
assume we want to implement this logic with c++ , what will be alternative to this line in c++?
malloc(sizeof(struct node));
struct node *newNode;
newNode = malloc(sizeof(struct node));
newNode->data = 4;
newNode->next = head;
head = newNode;