hi Nayeef below is the code which I wrote long back for finding a number in a list and replacing desired one
this is C code only using linked list.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define EXITSUCC 1;
#include <conio.h>
void push(struct node** , int i );
void insert(struct node** , int , int );
struct node
{
int data;
struct node* next;
};
void main()
{
int i;
struct node* head = malloc(sizeof(struct node));
struct node* ptr = malloc(sizeof(struct node));
struct node* temp = malloc(sizeof(struct node));
clrscr();
push(&head,0);
ptr = head;
for(i=1;i<=8;i++){
push(&(head->next),i);
head = head->next;
}
//storing for future use here....
temp = ptr;
while(ptr != NULL ){
printf("\n%d",ptr->data);
ptr = ptr->next;
}
printf("\n.....Want to insert data here.........\n");
insert(&temp,56,5);
printf("\n.........After Insert operation........\n");
while(temp != NULL ){
printf("\n%d",temp ->data);
temp = temp ->next;
}
getch();
}
void push(struct node** str,int data){
struct node* temp = malloc(sizeof(struct node));
temp -> data = data;
temp -> next = NULL;
*str = temp;
}
void insert(struct node** str, int n,int old){
struct node* temp = malloc(sizeof(struct node));
struct node* new1 = malloc(sizeof(struct node));
temp = *str;
while( temp!= NULL ){
if(temp->data == old){
new1 -> next = temp -> next;
new1 -> data = n;
temp -> next = new1;
return;
}
temp = temp->next;
}
}