search link list

#include"stdio.h"
#include"iostream.h"
#include"conio.h"
struct node
{
int data;
node *next;
};
class linklist
{
node *list,*nptr,*tptr;
public:
linklist()
{
list=NULL;
}
void newnode(int item);
void link();
void showdata();
void search(int item);
};
void linklist::newnode(int item)
{
nptr =new(node);
nptr->data=item;
nptr->next=NULL;
//link();
}
void linklist::link()
{
if(list==NULL)
{
list=nptr;
tptr=nptr;
}
else
{
tptr->next=nptr;
tptr=nptr;
}
}
void linklist::search(int item)
{
tptr=list;
while(tptr !=NULL)
{
if(tptr->data==item)
{
cout<<"Data Found !\n"; break; } tptr=tptr->next;
if(tptr==NULL)
cout<<"Data is not in the list\n"; } } void linklist::showdata() { node *curptr; curptr=list; while(curptr !=NULL) { cout<<" "<data;
curptr=curptr->next;
}
//cout<<" "<data;
}

int main()
{
int n,d;
linklist mylist;
cout<<"\n How many nodes you have ?\t"; cin>>n;
cout<<"\n Enter data for nodes :"; for(int i=0;i>d;
mylist.newnode(d);
mylist.link();
}
cout<<"data in the list :"; mylist.showdata(); int item; cout<<"\n Enter the data to be found: "; cin>>item;
cout<<"\n Search Result: ";
mylist.search(item);



return 0;
}
http://www.google.com.bd/search?q=search+link+list&pov=100366784536684831572&usg=__l-bqafYvVrd4O1wVprEd-7Upvu0=&hl=en

No comments:

Post a Comment

Followers

About Me

Dhaka, Dhaka, Bangladesh
..