public class Node<T>
{
public T Data { get; set; }
public Node<T> Next { get; set; }
public void Append(Node<T> node)
{
if (this.Next == null)
{
this.Next = node;
}
else
{
Next.Append(node);
}
}
public override string ToString()
{
string res = Data.ToString();
if (this.Next != null)
{
res += Next.ToString();
}
return res;
}
}
public class NodeList<T>
{
private Node<T> headNode;
public NodeList(Node<T> node)
{
headNode = node;
}
public NodeList()
{
}
public void Append(Node<T> node)
{
if (headNode == null)
{
headNode = node;
}
else
{
headNode.Append(node);
}
}
public void Reverse()
{
Node<T> value = null;
while (headNode != null)
{
Node<T> newNode = new Node<T>();
newNode.Data = headNode.Data;
newNode.Next = value;
value = newNode;
headNode = headNode.Next;
}
headNode = value;
}
public override string ToString()
{
if (headNode == null) return string.Empty;
else return headNode.ToString();
}
}