//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; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter