# Quiz 4

## Problem Statement:

It was another fine morning at Kinokuniya (the bookstore where Raphael works part-time). Raphael's employer was very happy with the program that he submitted thanks to your help and promised him a bonus if he also is able to manage the long queues to the register. The employer wants to be able to:

1. Add new people to the back of the queue,
2. Print the name of the person in the front, and remove him/her from the front of the queue,
3. Search for a specific person in the queue,
4. Print the entire queue.
5. Being the diligent worker he is, Raphael has already started writing code for this. He has started implementing a linked list in C++, and has written functions for 1 and 4. Help him finish the implementation by writing functions for 2 and 3. His code is available here. Refer to the comments in the .cpp file for his outline on how he thinks you should implement functions 2 and 3.

## Solution

This quiz asks you to basically implement linked lists using C-type code. I used it as a first-time introduction to linked lists.
```#include <iostream>
#include <string>
using namespace std;

typedef struct node
{
string name;
struct node* next;
} node_t;

/*-----
* Function to take a name and add a new node to the list given by node_t* head.
* It returns back the updated list.
* -----
*/
{
node_t* newNode = new node_t;
newNode->next = NULL;
if(head == NULL) // If the list is empty
{
}
else // If the list is already populated, traverse to the end of the list and add newNode there.
{
while(p->next!=NULL)
{
p = p->next;
}
p->next = newNode;
}
}

/*-----
* Function to print the name of the person at front, and remove him/her from the list.
* This function should not do anything if the list is empty.
* -----
*/
{
{
cout << "List is empty!" << endl;
return NULL;
}
else
{
cout << "Person at front: " << head->name << endl;
node_t* p = head;	// Keep a copy of head before deleting it!
delete p;
}
}

/*-----
*  Function to search for a specific person in the list node_t* head.
*  If said person is found, function should return the position of this person from the front.
*  -----
*/
{
int position = 1;
while(p!=NULL)
{
if(p->name == searchName)
{
cout << "Person " << searchName << " found at position " << position << " in the queue!\n";
return position;
}
p = p->next;
}
// If we reach here, that means the while loop has ended without the function terminating. This means searchName was not found in the list.
return -1;
}

// Function to print the entire contents of the queue
{
{
cout << "List is empty!" << endl;
return;
}
cout << "The current list is:\n";
do
{
cout << p->name << endl;
p = p->next;
}while(p!=NULL);
}

int main()
{