This code builds a simple linked list containing integers from 0 to 100. How do I implement a search that searches the list for the node that contains a particular value entered by the user and retus the location in the linked list where the number was found?
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *link;
}Node;
void dispnodes(Node *first);
Node* insertrear(Node *first,int a);
void sum(Node *first);
int main() {
int i;
struct node *first=NULL;
for(i=0;i<=100;i++)
first=insertrear(first,i);
dispnodes(first);
sum(first);
retu 0;
}
Node* getnode(Node *temp,int i)
{
temp=(Node*)malloc(sizeof(Node));
temp->data=i;
temp->link=NULL;
retu temp;
}
Node* insertrear(Node *first,int a)
{
Node *temp=NULL,*i;
temp= getnode(temp,a);
if(first==NULL)
{
first=temp;
retu first;
}
for(i=first;i->link!=NULL;i=i->link);
i->link=temp;
retu first;
}
void dispnodes(Node *first)
{
int j;
if(first==NULL)
{
printf("nlist empty");
retu;
}
Node *i;
for(i=first,j=0;i!=NULL;j++,i=i->link)
printf("nNode #%d contains %d ",j,i->data);
}
void sum(Node *first)
{
Node *i;
int total=0;
for(i=first;i!=NULL;i=i->link)
total+=i->data;
printf("nThe sum total of all nodes in this list is %d",total);
}
