186: Inserting a new node in a linked list (logic)

PHOTO EMBED

Tue May 23 2023 17:28:53 GMT+0000 (Coordinated Universal Time)

Saved by @saakshi #c++

//inserting a new node at the first; at the head of the linked list

Node *t = new Node;
t->data=x;
t->next = first;
first= t;

//inserting a new node after a given node
Node *t= new Node;
t->data= x;
p=first;
for(i=0; i<pos-1; i++){
  p =p->next;
  t->next= p->next;
  p->next= t;
}
content_copyCOPY