#include "LIST.h"
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

LIST::LIST()
{
	front='\0';

}

bool LIST::IsEmpty()
{
	if(front=='\0')
	{
		return true;
	}
	else
	{   
		return false;
	}
}

void LIST::insert(record & rec)
{
	record * p = new record;
	
	p->lastname=rec.lastname;											
	p->firstname=rec.firstname;
	p->address=rec.address;
	p->phone=rec.phone; 
	p->next=0;

	if (front==0)										
	{
		front=p;									
	}
	else												
	{
		back->next=p;									
		back= p;										
	}
}

void LIST::delete_record(record * R)
{
	if(R == front) 
	{
	    front = R->next;
	    delete R;
	} 
	else 
	{
	    record *p = front;
	    while(p) 
	    {
	        if(p->next == R) 
	        {	            
	            P->next = R->next;	            
	            if(R == back) 
	            {
	                back = P;    
	            }
	            delete R;
	            break;
	        }
	        p = p->next;
	    }
	}
	/*
	record * p= front;									//creates pointer p that points to the front
	R=front;											//inode pointer last also points to front

	if(front!=0)										
	{
		
		p=front;

		record *b=front;									
		while(p!=R)									
		{
			b=p;										
			p=p->next;									
		}

		if(p==front)									
		{
			front=front->next;							  
			delete p;									
		}
		else if(p==back)								
		{
			back=b;										 
			back->next=0;								
			delete p;								
		}
		else
		{
			b->next=p->next;							
			delete p;									
		}
	}								
    */
}
