#include "Person.h"

struct Node
{
	Person person;
	Node* next;
};

class List 
{
	public:
		List()
		{
			length = 0;
			head = NULL;
		}
		int getLength()
		{
			return length;
		}
		void put(Person person)
		{
			Node* newNode = new Node();
			newNode->person = person;
			newNode->next = head;
			head = newNode;
			length++;
		}
		void remove(int key) //removes a node with the given primary key
		{
			Node* location = head;
			Node* temp = new Node();
			
			if(key == head->person.getPrimaryKey())
			{
				temp = location;
				head = head->next;
			}
			else
			{
				while(location->next->person.getPrimaryKey != key)
					location = location->next;
					
				temp = location->next;
				location->next = location->next->next;
			}
			delete temp;
			length--;
		}
		void resetList()
		{
			current = NULL;
		}
		Person getNextPerson()
		{
			if (current == NULL)
				current = head;
			else
				current = current->next;
			return current->person;
		}
	private:
		Node* head;
		int length;
		Node* current;
		
};