Let $A,B,C,D,E,F$ be the data.

$A \rightarrow B \rightarrow C \rightarrow E \rightarrow F$

Let pointer to $E$ be $p$.

A node with data $D$ has to be inserted before $E$.

I'll do one thing - add $D$ just after node $E$ and it'll take constant time.

$p.{next} \rightarrow Address\_of\_D$

$Address\_of\_D.next \rightarrow Address\_of\_F$

$A \rightarrow B \rightarrow C \rightarrow E \rightarrow D \rightarrow F$

Take a temporary variable and swap the values $E$ and $D$..

$temp = p.data$

$p.data= p.next.data$

$p.next.data= temp$

Now linked list wil look like

$A \rightarrow B \rightarrow C \rightarrow D \rightarrow E \rightarrow F$

still one more work left - now pointer $p$ pointing to $D$ so increment pointer $p$ to point data $E$.

$p= p \rightarrow next$

void InsertBeforeGivenPointer(struct node* p, int D){
struct node* temp = (node*)malloc(sizeof(struct node));
temp->next = p->next;
p->next = temp;
temp->data = p->data;
p->data = D;
}