using System.Collections;
using System.Collections.Generic;
public static void Main()
LinkedList<int> linkedList = new LinkedList<int>();
foreach(var item in linkedList.Reverse())
foreach(var item in linkedList.ReverseUsingRecursion())
public static class MyLinq
public static LinkedList<T> Reverse<T>(this LinkedList<T> linkedList){
var head = linkedList.First;
while (head.Next != null)
linkedList.Remove(next.Data);
linkedList.AppendFirst(next.Data);
public static LinkedList<T> ReverseUsingRecursion<T>(this LinkedList<T> linkedList)
var head = linkedList.First;
if (head == null) return new LinkedList<T>();
var newLinkedList = new LinkedList<T>();
newLinkedList.AppendFirst(head.Data);
linkedList.Remove(head.Data);
linkedList.ReverseUsingRecursion();
public T Data { get; set; }
public Node<T> Next { get; set; }
public class LinkedList<T> : IEnumerable<T>
Node<T> node = new Node<T>(data);
public bool Remove(T data)
if (current.Data.Equals(data))
previous.Next = current.Next;
if (current.Next == null)
public Node<T> First { get { return head; } }
public Node<T> Last { get { return tail; } }
public int Count { get { return count; } }
public bool IsEmpty { get { return count == 0; } }
public bool Contains(T data)
if (current.Data.Equals(data))
public void AppendFirst(T data)
Node<T> node = new Node<T>(data);
IEnumerator IEnumerable.GetEnumerator()
return ((IEnumerable)this).GetEnumerator();
IEnumerator<T> IEnumerable<T>.GetEnumerator()
yield return current.Data;