using System; using System.Linq; using System.Text; using System.Threading.Tasks; using C_.Datastructures.Nodes; namespace C_.Datastructures { internal class DoublyLinkedList { internal DoublyLinkedListNode? Head { get; set; } = default; internal DoublyLinkedListNode? Tail { get; set; } = default; private int Count { get; set; } = 0; public static DoublyLinkedList Create() { //Create a new empty list return new DoublyLinkedList(); } public static DoublyLinkedList Create(T value) { //Create a new Class with a single item return new DoublyLinkedList() { Head = DoublyLinkedListNode.Create(value, null, null), Count = 1 }; } public T? this[int i] { get { //Check Range if (i >= Count) throw new System.Exception("Error! Index out of Bounds"); //Return Value DoublyLinkedListNode? node = Traverse(i); if (node != null) return node.Value; return default; } set { //Check Range if (i >= Count) throw new System.Exception("Error! Index out of Bounds"); //Change Value DoublyLinkedListNode? node = Traverse(i); node!.Value = value; } } private DoublyLinkedListNode? Traverse() { //Return the final item in the list return Tail; } private DoublyLinkedListNode? Traverse(int i) { //Determine whether to start at the start or end of the list int direction = 1; DoublyLinkedListNode? node = Head; if (i > (Count/2)) { direction = -1; node = Tail; i = Count - i; } if (node != null) { //continue to end of list for (int x = 0; x < i; x++) { //Incomplete Traverse Functions } } return node; } private DoublyLinkedListNode? Next(DoublyLinkedListNode current) { if (current != null) return current.Next; return null; } private DoublyLinkedListNode? Prev(DoublyLinkedListNode current) { if (current != null) return current.Prev; return null; } } }