private static DoublyLinkedList Reverse(DoublyLinkedList dll) { var p = dll.Head; dll.Tail = p; while (p != null) { var temp = p.Next; p.Next = p.Previous; p.Previous = temp; if (p.Previous == null) { dll.Head = p; } p = p.Previous; } return(dll); }
public static DoublyLinkedList CreateDoublyLinkedList(int[] numArray) { var dll = new DoublyLinkedList(numArray.Length); var node = new DoublyNode(); node.Value = numArray[0]; node.Previous = null; node.Next = null; dll.Head = node; dll.Tail = node; for (int i = 1; i < numArray.Length; i++) { var temp = new DoublyNode(); temp.Value = numArray[i]; temp.Next = null; temp.Previous = dll.Tail; dll.Tail.Next = temp; dll.Tail = temp; } return(dll); }
private static DoublyLinkedList InsertDoublyNodeAtNPosition(DoublyLinkedList dll, int position) { var node = new DoublyNode(); node.Value = 500; var temp = dll.Head; for (int i = 1; i < position - 1; i++) { temp = temp.Next; } //var nodeToDelete = temp.Next; node.Previous = temp; node.Next = temp.Next; temp.Next = node; if (node.Next != null) { node.Next.Previous = node; } return(dll); }