May 5, 2012 at 4:16pm UTC
Hi guys
i cant find a search functin for a linked list that searches a linked list for a name that the user puts in.
i tried google and many other site cant find a smiple code..
Thanks
May 5, 2012 at 4:41pm UTC
You simply need to iterate through the list?
May 5, 2012 at 4:47pm UTC
look bro thats my code
my problem in find
""compare serchedname with name ""
#include <iostream.h>
#include <string.h>
class list{
char name[20];
list *next;
public:
void add();
void print();
int find();
};
list *head=NULL;
void list::add()
{
list *node=new list;
cin >> node->name;
node->next=NULL;
if(head==NULL)
head=node;
else{
node->next=head;
head=node;
}
}
void list::print(){
list *c=head;
while(c!=NULL)
{
cout << c->name<<"\t";
c=c->next;
}}
int list::find(){
list *f=head;
char searchname[20];
cout << "enter c value : ";
cin >> searchname;
/* here is my problem */
}
void main(){
list l;
for(int i=0;i<2;i++)
l.add();
l.print();
cout <<endl << l.find();
}