public int?RemoveFromBack() { if (Tail == null) { Console.WriteLine("List is empty"); return(null); } int val = Tail.Value; Tail = Tail.Previous; Tail.Next = null; Console.WriteLine(val); return(val); }
public DLL AddToFront(int val) { DLNode newNode = new DLNode(val); if (Head == null) { Head = newNode; Tail = newNode; return(this); } Head.Previous = newNode; newNode.Next = Head; Head = newNode; return(this); }
// DLL Class // Given the above reference implementations for doubly linked node and doubly linked list, can you construct the rest of a basic DList class? This would include DList methods push(), pop(), front(), back(), contains(), and size(). public DLL AddToBack(int val) { DLNode newNode = new DLNode(val); if (Head == null) { Head = newNode; Tail = newNode; return(this); } Tail.Next = newNode; newNode.Previous = Tail; Tail = newNode; return(this); }
// DList: Reverse // Create function to reverse nodes in a DList. public DLL Reverse() { DLNode Runner = Head; while (Runner != null) { DLNode Temp = Runner.Next; Runner.Next = Runner.Previous; Runner.Previous = Temp; Runner = Temp; } DLNode Temp2 = Head; Head = Tail; Tail = Temp2; return(this); }
public DLL Reverse2() { List <int> Values = new List <int>(); DLNode Runner = Head; while (Runner != null) { Values.Add(Runner.Value); Runner = Runner.Next; } Runner = Tail; foreach (int Value in Values) { Runner.Value = Value; Runner = Runner.Previous; } return(this); }
public DLL() { Head = null; Tail = null; }