public void Reverse() { if (Head == null) { Console.WriteLine("there aren't any nodes in the list!"); } else { DLLNode runner = Head; while (runner.Next != null) { runner = runner.Next; } DLLNode start = runner; runner.Next = runner.Prev; runner.Prev = null; while (runner.Next != Head) { DLLNode temp = runner.Next; temp.Next = temp.Prev; temp.Prev = runner; runner = temp; } Head.Prev = runner; Head.Next = null; Head = start; } }
public void PrintValues() { if (Head == null) { Console.WriteLine("there isn't a list!"); } else { DLLNode runner = Head; while (runner.Next != null) { Console.WriteLine(runner.Value); runner = runner.Next; } Console.WriteLine(runner.Value); } }
public void Add(int value) { DLLNode newNode = new DLLNode(value); if (Head == null) { Head = newNode; } else { DLLNode runner = Head; while (runner.Next != null) { runner = runner.Next; } runner.Next = newNode; newNode.Prev = runner; } }
public void Remove(int value) { if (Head == null) { Console.WriteLine("there aren't any nodes in the list!"); } else { if (Head.Value == value) { if (Head.Next == null) { Head = null; } else { Head = Head.Next; Head.Prev = null; } } else { DLLNode runner = Head; while (runner.Next.Next != null) { if (runner.Next.Value == value) { runner.Next = runner.Next.Next; runner.Next.Next.Prev = runner; break; } runner = runner.Next; } } } }
public DoublyLinkedList() { Head = null; }
public DLLNode(int val) { Value = val; Next = null; Prev = null; }