start allocate memory for the new node and initialize its data part to take two pointer variables ptr and preptr and initialize them with start so that startptrand preptr point to the first node of the list start ptr preptr move ptr and preptr until the data part of preptr value of the node after which insertion has to be done preptr will always point to the node just before ptr start preptr ptr start preptr ptr add the new node in between the nodes pointed by preptr and ptr start preptr ptr new_node start figure inserting an element after given node in linked list inserting node before given node in linked list consider the linked list shown in fig suppose we want to add new node with value before the node containing before discussing step if avail null the changes that will be done in the linked write overflow listlet us first look at the algorithm shown go to step in fig [end of ifstep set new_node avail in step we take pointer variable step set avail avail next ptr and initialize it with start that isptr step set new_node data val now points to the first node of the linked step set ptr start list thenwe take another pointer variable step set preptr ptr step repeat steps and while ptr data !num preptr and initialize it with ptr so nowstep set preptr ptr ptrpreptrand start are all pointing to step set ptr ptr next the first node of the linked list [end of loopin the while loopwe traverse through step preptr next new_node step set new_node next ptr the linked list to reach the node that has step exit its value equal to num we need to reach this node because the new node will be figure algorithm to insert new node before node that has inserted before this node once we reach value num