How to find and replace a node in Linked List

For replacing an element in a linked list first we have to find it , for that we will use a function which will do the finding part and give us the node's address (pointer) and then we will replace the value of that node by the value given by the user. Definition of node* find_pos(int) function node* find_pos(int val,int p){ node* cur=first; node* prev=cur; while(cur->val!=val){ prev=cur; cur=cur->next; if(cur==NULL)return NULL; } switch(p){ case 0: return cur; case 1: return cur->next; default:return prev; } } The above function keeps track of the previous node and keep traversing through the linked list until we find the value which is to be replaced, it return the previous node if value of p is -1 or returns current node if p=0 or next one if p=1. Definition of find_replace function void find_replace(int find,int replace){ int c=0; while(node *temp=find_pos(find,0)