Create linked list template with loop detection