#include<iostream.h>
#include<conio.h>
struct node
{
int info;
node *link;
};
void main()
{
clrscr();
cout<<"\n ------- Linked List Searching -------\n\n";
node a[100];
node *start=&a[1];
int n,i,item,s=0;
cout<<"Enter No. of Nodes in Linked List : ";
cin>>n;
cout<<"Enter Info of Nodes :\n";
for(i=1;i<=n;i++)
{
cout<<"Node "<<i<<" : ";
cin>>a[i].info;
a[i].link=&a[i+1];
}
a[n].link=0;
cout<<"\nEnter Item you want to Search : ";
cin>>item;
i=1;
while(start!=0)
{
if(item==a[i].info)
{
cout<<"Item is Found at Position : "<<i;
s=1;
break;
}
else
{
i++;
start=start->link;
}
}
if(s==0)
{
cout<<"Item is Not Found";
}
getch();
}
Output :-
0 comments:
Post a Comment