// node is a struct containing an int and next pointer void insert(int D, node* p){ node* temp = (node*)malloc(sizeof(node)); temp->next = p->next; // make temp point to the node where p was pointing p->next = temp; // attach node temp next to node p /*till this point it is simialr to inserting node after a node whose pointer p is given. Now change the data of both nodes p and temp to get desired result*/ temp->data = p->data; // copy the data of current node to new node p->data = D; }