Answer:
Step-by-step explanation:
#include <bits/stdc++.h>
using namespace std;
/* Link list node */
class Node
{
public:
string Name;
long Library_card_number;
string Street;
string City;
long Zip;
Node* next;
};
/* Given a reference (pointer to pointer) to the head
of a list and an int, push a new node on the front
of the list. */
void push(Node** head_ref,string name,long lcn,string street,string city,long zip)
{
/* allocate node */
Node* new_node = new Node();
/* put in the key */
new_node->Name = name;
new_node->Library_card_number = lcn;
new_node->Street = street;
new_node->City = city;
new_node->Zip = zip;
/* link the old list off the new node */
new_node->next = (*head_ref);
/* move the head to point to the new node */
(*head_ref) = new_node;
}
/* Checks whether the value x is present in linked list */
Node* search(Node* head, string x)
{
Node* current = head; // Initialize current
while (current != NULL)
{
if (current->Name == x)
return current;
current = current->next;
}
return NULL;
}
/* Driver program to test count function*/
int main()
{
/* Start with the empty list */
Node* head = NULL;
int x = 21;
/* Use push() to construct below list
14->21->11->30->10 */
push(&head, "Joe",1,"hippy Street","Bay area",2009);
push(&head, "Marie",2,"lippy street","san jose",2010);
push(&head, "Harry",3,"gippy Street","Bay area",2009);
push(&head, "Ashish",4,"dippy street","san jose",2010);
push(&head, "Zuck",5,"sippy Street","Bay area",2009);
push(&head, "Gates",6,"kippy street","san jose",2010);
push(&head, "Page",7,"pippy Street","Bay area",2009);
push(&head, "Brin",8,"dippy street","san jose",2010);
string name;
cout<<"Enter name of the person to search: ";
cin>>name;
Node* z = search(head,name);
if(z!=NULL){
cout<<"\\Person found in the list"<<endl;
cout<<"Name: "<<z->Name<<endl;
cout<<"Library Card Number: "<<z->Library_card_number<<endl;
cout<<"Street: "<<z->Street<<endl;
cout<<"City: "<<z->City<<endl;
cout<<"Zip: "<<z->Zip<<endl;
}else{
cout<<"No person found with the name "<<name<<endl;
}
return 0;
}