Class Kata "Linked List"
Develop the abstract data type List in the form of a linked list. The class to be implemented LinkedList the interface must IList implement.
A linked list consists of elements that each contain a value and a pointer to the next element in the list:
class Element { public Element(T item) { Item = item; } public T Item { get; set; } public Element Next { get; set; } }
The list is composed of these elements internally. The elements are not visible to the outside world. The LinkedList behaves like other classes that IList implement:
class LinkedList : IList { ... }
Variations
The list can also be double-linked. In addition to the Next property of the element, these are given a Prev Property for the reference to the previous element. This speeds up traversing backwards from the last to the first element.
class Element { public Element(T item) { Item = item; } public T Item { get; set; } public Element Next { get; set; } public Element Prev { get; set; } }