#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//type dfinitions
typedef struct lin_list
	{
	char *value;
	struct lin_list *next;
	}LinListCell, *LinList_p;

//function derfinitions

LinList_p LinListAllocCell(char* value);
void LinListFreeCell(LinList_p junk);
void LinListFree(LinList_p *junk);
LinList_p LinListInsertFirst(LinList_p anchor,LinList_p newCell);
LinList_p LinListExtractFirst(LinList_p *anchor);
LinList_p LinListFind(LinList_p anchor, char* value);

int main(void)
{
	LinList_p anchor = LinListAllocCell("xx");
	anchor->next =  LinListAllocCell("xc");
	printf("anchor=%p\n",anchor);
	printf("%p %p \n", anchor->value,anchor->next->value);
}


LinList_p LinListFind(LinList_p anchor, char* value)
{
LinList_p cell = anchor;
while(cell != NULL)
	{
	if(strcmp(value, cell->value)!=0)
		{
		return NULL;
		}else
		{
		return cell;
		}
	cell = cell->next;
	}
}


LinList_p LinListExtractFirst(LinList_p *anchor)
{
LinList_p buff = anchor;
*anchor = anchor->next
return buff;
}

LinList_p LinListInsertFirst(LinList_p anchor,LinList_p newCell)
{
	LinListCell *buff = anchor;
	anchor = LinListAllocCell("");
	anchor->next = buff;
}

LinList_p LinListAllocCell(char* value)

{
	LinList_p newcell = malloc(sizeof(LinListCell));
	newcell->next = NULL;
	newcell->value = strdup(value);
	return newcell;
}


void LinListFreeCell(LinList_p junk)
{
	free(junk);
}

void LinListFree(LinList_p *junk)
{
	LinListCell  *next = junk;
	LinListCell *buff;
	*junk = NULL;
	while(next != NULL)
	{
		buff = next->next;
		free(next);
	}
}
