searching element in unsorted link list


//searching an element from an unsorted link list
#include<iostream.h>
#include<conio.h>
typedef struct node
{
int data;
struct node *link;
}NODE;
void main()
{
NODE *ptr,*prev,*start;
start=NULL;
clrscr();
cout<<"\nEnter 10 elements in array\n";
for(int i=0;i<10;i++)
{
ptr=new NODE();
cin>>ptr->data;
ptr->link=NULL;
if(start==NULL)
{
start=ptr;
}
else
{
prev->link=ptr;
}
prev=ptr;
}
//searching elements from unsort list
int item;
cout<<"\nEnter element to be search \n";
cin>>item;
ptr=start;
int f=0;
NODE *loc;
for(i=0;i<10;i++,ptr=ptr->link)
{
if(item==ptr->data)
{
f=1;
loc=ptr;
break;
}
}
if(f==1)
cout<<"\nitem searched successfully at "<<loc;
else
cout<<"\nitem not find";
getch();
}

*******output*******

Enter 10 elements in array
2
3
15
65
48
9
62
14
75
33

Enter element to be search
62

item searched successfully at 0x8fa40f46

No comments:

Post a Comment

using avrdude with AVR studio(for windows 10 only)

Requirements 1. arduino-1.6.5-r2-windows.exe 2. as6installer-6.0.1843.exe When I try to configure avrdude in avr studio 6 then wina...