public DLNode Start(DLNode root) { Convert(root); DLNode temp = DLLast; while (temp.Left != null) { temp = temp.Left; } return(temp); }
public void InOrder(DLNode root) { if (root.Left != null) { InOrder(root.Left); } if (root.Right != null) { InOrder(root.Right); } Console.Write(root.Value + " "); }
public void PrintTravers(bool direct) { Queue <DLNode> temp; Queue <DLNode> next; if (tempR.Count == 0 && tempL.Count == 0) { return; } if (direct) { temp = tempR; next = tempL; } else { temp = tempL; next = tempR; } while (temp.Count > 0) { DLNode root = temp.Dequeue(); Console.Write(root.Value + " "); if (direct) { if (root.Left != null) { next.Enqueue(root.Left); } if (root.Right != null) { next.Enqueue(root.Right); } } else { if (root.Right != null) { next.Enqueue(root.Right); } if (root.Left != null) { next.Enqueue(root.Left); } } } PrintTravers(!direct); }
public DLNode Inint() { DLNode A = new DLNode(10); DLNode B = new DLNode(12); DLNode C = new DLNode(15); DLNode D = new DLNode(25); DLNode E = new DLNode(30); DLNode F = new DLNode(36); A.Left = B; A.Right = C; B.Left = D; B.Right = E; C.Left = F; return(A); }
public DLNode Init() { DLNode A1 = new DLNode(1); DLNode A2 = new DLNode(2); DLNode A3 = new DLNode(3); DLNode A4 = new DLNode(4); DLNode A5 = new DLNode(5); DLNode A6 = new DLNode(6); DLNode A7 = new DLNode(7); A1.Left = A2; A1.Right = A3; A2.Left = A4; A2.Right = A5; A3.Left = A6; A3.Right = A7; return(A1); }
public void BFS(DLNode root) { Queue <DLNode> bfsQ = new Queue <DLNode>(); bfsQ.Enqueue(root); while (bfsQ.Count > 0) { DLNode temp = bfsQ.Dequeue(); Console.Write(temp.Value + " "); if (temp.Left != null) { bfsQ.Enqueue(temp.Left); } if (temp.Right != null) { bfsQ.Enqueue(temp.Right); } } }
public void Convert(DLNode curr) { if (curr == null) { return; } Convert(curr.Left); if (DLLast == null) { DLLast = curr; } else { DLLast.Right = curr; curr.Left = DLLast; DLLast = curr; } Convert(curr.Right); }
public void AddToCache(int A) { if (ht.Contains(A)) { DLNode temp = (DLNode)ht[A]; if (temp.Left != null) { temp.Left.Right = temp.Right; } if (temp.Right != null) { temp.Right.Left = temp.Left; } temp.Right = queStart; queStart.Left = temp; queStart = temp; } else { DLNode newNode = new MS.DLNode(A); if (queStart != null) { queStart.Left = newNode; newNode.Right = queStart; } queStart = newNode; } if (ht.Count > QueSize) { DLNode remove = queStart; while (remove.Right != null) { remove = remove.Right; } remove.Left.Right = null; ht.Remove(remove.Value); } //Done }