using System;
using System.Collections.Generic;
public class MainClass
{
static void Main(string[] args)
{
// create list
var list = new LinkedList<int>(new[] { 1, 2, 3, 4 });
// reverse list
var n = list.First; // start from first which will remain constant in the list
while (n.Next != null) // at the end current will point to null
{
var current = n.Next; // store next n
list.Remove(current); // remove next n after current
list.AddFirst(current.Value); // place next value at the start
}
// display reversed list
foreach (int node in list)
{
Console.WriteLine($"{node}");
}
}
}