node *alloc_node(int Value, int x, int y, node *Next)
{
  	node *NewNode = malloc(sizeof(node));
  	NewNode->Value = Value;
	NewNode->x = x;
	NewNode->y = y;
  	NewNode->Next = Next;
  
	return NewNode;
}

void list_add(node **Head, int Value, int x, int y)
{
  	node *NewNode = alloc_node(Value, x, y, *Head);
	*Head = NewNode;
}

node *list_get(node **Head, int x, int y)
{
	for(node *Iter = *Head; Iter; Iter = Iter->Next)
	{
		if(Iter->x == x && Iter->y == y)
		{
			return Iter;
		}
	}
	return 0;
}

void list_remove(node **Head, node *Node)
{
	node *Prev = 0;
  	for(node *Iter = *Head; Iter; Iter = Iter->Next)
	{
		if(Iter == Node)
			break; 
		Prev = Iter;
	}
  	if(Prev)
		Prev->Next = Node->Next;
	free(Node);
}

void list_free(node **Head)
{
	for(node *Iter = *Head; Iter; )
	{
		node *ToFree = Iter;
		Iter = Iter->Next;
      
		free(ToFree);
	}
}
