#include
#include
#include
struct node
{
int info;
struct node *link;
};
typedef struct node NODE;
NODE *head;
/*Fucntion to create a linked lsit*/
void create_link_list(NODE *CurrPtr)
{
NODE *NewNode;
int ans;
while(1)
{
printf("\nEnter info :");
scanf("%d",&CurrPtr->info);
printf("\nDo u wish to enter one more node press 1 :");
scanf("%d",&ans);
if(ans==1)
{
NewNode=(NODE*)(malloc(sizeof(NODE)));
CurrPtr->link=NewNode;
CurrPtr=NewNode;
}
else
{
CurrPtr->link=NULL;
break;
}
}
}
void display(NODE *CurrPtr)
{
CurrPtr=head;
while(CurrPtr!=NULL)
{
printf("\n%d",CurrPtr->info);
CurrPtr=CurrPtr->link;
}
}
NODE *linsearch(NODE *CurrPtr,int item)
{
while(CurrPtr!=NULL)
{
if(item==CurrPtr->info)
return(CurrPtr);
CurrPtr=CurrPtr->link;
}
return NULL;
}
void main()
{
int item;
clrscr();
head=(NODE*)malloc(sizeof(NODE));
create_link_list(head);
printf("\n LINKED LIST ELEMENTS ARE :");
display(head);
printf("\n Enter an item to be search");
scanf("%d",&item);
if(linsearch(head,item)==NULL)
printf("\n %d does not exist");
else
printf("\n %d is exist");
}
No comments:
Post a Comment