public static void Main()
listNode head = new listNode { Value = 1 };
head = AddSentinalToHead(head);
listNode tail = AddSentinalToTail(head);
while (head.Next != null && head.Next != tail) {
Console.WriteLine(head.Next.Value);
public int Value { get; set; }
public listNode Next { get; set; }
public listNode Prev { get; set; }
public static listNode AddSentinalToHead(listNode head)
listNode newNode = new listNode { Next = head };
public static void AddSentinalToHead(ref listNode head)
listNode newNode = new listNode { Next = head };
public static listNode AddSentinalToTail(listNode head)
listNode newNode = new listNode();
while (head.Next != null)
public static void AddNodeToStart(listNode head, int val)
listNode newNode = new listNode { Value = val };
newNode.Next = head.Next;
newNode.Next.Prev = newNode;
public static void AddNodeToEnd(listNode tail, int val)
listNode newNode = new listNode { Value = val };
newNode.Prev = tail.Prev;
newNode.Prev.Next = newNode;
public static void AddNodeAfter(listNode node, int val)
listNode newNode = new listNode { Value = val };
newNode.Next = node.Next;
newNode.Next.Prev = newNode;
public static void AddNodeBefore(listNode node, int val)
listNode newNode = new listNode { Value = val };
newNode.Prev = node.Prev;
newNode.Prev.Next = newNode;
public static void DeleteNodeAfter(listNode node)
node.Next = node.Next.Next;
public static void DeleteNodeBefore(listNode node)
node.Prev = node.Prev.Prev;
public static listNode FindNodeByValue(listNode head, int val)
while (head.Next != null)
if (head.Next.Value == val)
public static listNode FindPrevNodeByValue(listNode head, int val)
while (head.Next != null)
if (head.Next.Value == val)