class CustomCircularLinkedList<T>
{
public CircularLinkedListItem<T> RootNode;
public int Count { set; get; }
public void Add(T value)
{
CircularLinkedListItem<T> newNode = new CircularLinkedListItem<T>(value);
if (RootNode == null)
{
this.RootNode = newNode;
Count++;
return;
}
CircularLinkedListItem<T> node = this.RootNode;
while (node.NextNode != null)
{
node = node.NextNode;
}
node.NextNode = newNode;
newNode.PreviousNode = node;
//This distinguishes double and circular linkedlist
this.RootNode.PreviousNode = newNode;
}
}
class CircularLinkedListItem<T>
{
public CircularLinkedListItem<T> PreviousNode { set; get; }
public CircularLinkedListItem<T> NextNode { set; get; }
public T NodeItem { set; get; }
public CircularLinkedListItem(T value)
{
this.NodeItem = value;
}
}
{
public CircularLinkedListItem<T> RootNode;
public int Count { set; get; }
public void Add(T value)
{
CircularLinkedListItem<T> newNode = new CircularLinkedListItem<T>(value);
if (RootNode == null)
{
this.RootNode = newNode;
Count++;
return;
}
CircularLinkedListItem<T> node = this.RootNode;
while (node.NextNode != null)
{
node = node.NextNode;
}
node.NextNode = newNode;
newNode.PreviousNode = node;
//This distinguishes double and circular linkedlist
this.RootNode.PreviousNode = newNode;
}
}
class CircularLinkedListItem<T>
{
public CircularLinkedListItem<T> PreviousNode { set; get; }
public CircularLinkedListItem<T> NextNode { set; get; }
public T NodeItem { set; get; }
public CircularLinkedListItem(T value)
{
this.NodeItem = value;
}
}