public static void Main()
var nodes1 = new ListNode<string>("1", new ListNode<string>("2", new ListNode<string>("3", new ListNode<string>
("4", new ListNode<string>("5", new ListNode<string>("6", null))))));
var nodes2 = new ListNode<string>("1", new ListNode<string>("2", new ListNode<string>("3", new ListNode<string>
("4", new ListNode<string>("5", new ListNode<string>("6", new ListNode<string>("12", new ListNode<string>("11", new ListNode<string>("13", null)))))))));
var findNode = new ListNode<string>("5", null);
var node = new ListNode<string>("11", null);
Console.WriteLine("Замена элемента в списке");
Replace<string>(findNode, node, ref nodes1);
printList<string>(nodes1);
Console.WriteLine("Объединение первого и второго списка");
Merger<string>(ref nodes1, ref nodes2);
printList<string>(nodes1);
public static void Replace<T>(ListNode<T> t, ListNode<T> r, ref ListNode<T> v)
Console.WriteLine(v.Value);
if (v.Value.Equals(t.Value))
Console.WriteLine("Меняем {0} на {1}", v.Value, r.Value);
Replace<T>(t, r, ref v.Next);
public static void Merger<T>(ref ListNode<T> s, ref ListNode<T> v)
for (var i = s; i != null; i = i.Next)
if (i.Value.Equals(v.Value))
if (!h && i.Next == null)
i.Next = new ListNode<T>(v.Value, null);
Merger<T>(ref s, ref v.Next);
public static void printList<T>(ListNode<T> v)
Console.WriteLine(v.Value);
public ListNode(T value, ListNode<T> next)
public string NodeName { get; set; }