I need a search function for this

I need help. PLease! The program's requirement is to have a search function using linked list. Thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream.h>
#include<iomanip>
#include<string>
#include<windows.h>

using namespace std;


const int y=18;
struct Employee
{
    char name[y];
    char telno[y];
    char add[y];
    
    Employee *nextAddr;
   
};
void display (Employee *);
int main()
{
	HANDLE hConsole;
	COORD size;
	HWND hWnd;
		
	hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	size = GetLargestConsoleWindowSize(hConsole);
	SetConsoleScreenBufferSize(hConsole,size);
	SetConsoleTitle("test");
	hWnd = FindWindow(NULL,"test");
	
	ShowWindow(hWnd,SW_MAXIMIZE);


Employee emp[]={
        {"Jerald Gellido ","C Raymundo Pasig ","09276288215"},
        {"Joseph Penolio ","Greenwoods,Cainta","09227779646"},
        {"Ivy Araullo    ","Taytay,Rizal     ","09157610739"},
        {"LA Amascual    ","Paranaque        ","09234357649"},
        {"Ruel Espares   ","Project 8,QC     ","09264257289"},
        {"Abigail Benito ","San Miguel,Pasig ","09332568932"},
        {"Jessica Canlas ","Greenwoods,Cainta","09227779646"},
        {"Niccolo Sanchez","Maybunga,Pasig   ","09282227676"},
        {"Angelo DelaCruz","Sagad, Pasig     ","09278882222"},
        {"Grace Marquez  ","Sagad, Pasig     ","09284357649"}};
   cout<<"   EMPNAME      CONTACT NO.	ADDRESS"<<endl;
    Employee *first;

    first=&emp[0];
    emp[0].nextAddr=&emp[1];
    emp[1].nextAddr=&emp[2];
    emp[2].nextAddr=&emp[3];
    emp[3].nextAddr=&emp[4];
    emp[4].nextAddr=&emp[5];
    emp[5].nextAddr=&emp[6];
    emp[6].nextAddr=&emp[7];
    emp[7].nextAddr=&emp[8];
    emp[8].nextAddr=&emp[9];
    emp[9].nextAddr=NULL;

    display(first);
    return 0;
}
void display(Employee *laman)
{
    while(laman != NULL)
    {
        cout<<laman->name<<"  "<<laman->add<<"  "<<laman->telno<<"  "<<endl;
        laman=laman->nextAddr;
    }
    cout<<endl;
	cout<<"Enter Name to be searched:     ";
	cout<<endl;
    return;

}
You haven't provided a search attempt at all. Still, I'll say this much: Your linked list is forward-only and the data is not sorted. This leaves you with one possible solution: Sequential search.

Sequential search means that you just start at the top of the list and compare the given name with the names stored in the linked list. If there is a match, you return that match; if there is no match you return a null pointer.
Topic archived. No new replies allowed.