public object Pop() { if (count == 0) throw new Exception("Stack is empty"); Node current = top; top = top.Next; count--; return current.Data; }
public void Push(object item) { Node newNode = new Node(item); if (top == null) { top = newNode; } else { Node temp = top; top = newNode; top.Next = temp; } count++; }
static ulong FindMaxPath(Node root) { foreach (var child in root.Children) { root.PathLengths.Add(FindMaxPath(child)); } if (root.PathLengths.Count != 0) { return root.Value + root.PathLengths.Max(); } else { return root.Value; } }
public CbinaryTree(byte[] in_data) { try { sum_nodes = CountNodes(in_data); nodes = new Node[sum_nodes]; depth_reaf_num = (byte[])in_data.Clone(); for (int i = 0; i < sum_nodes; i++) { nodes[i] = new Node(); } MakeDepthTable(in_data); CountReaves(in_data); SetNodes(in_data); SetTReaf(); } catch { Console.WriteLine(""); } }
public Node Pop() { if (Head == null) return null; Node poppedNode = Head; Head = Head.Next; return poppedNode; }
public void Push(Node node) { node.Next = Head; Head = node; }
public void AddChild(Node child) { this.Children.Add(child); this.HasChildren = true; child.HasParent = true; }
public void Clear() { this.top = null; this.count = 0; }
public Stack() { this.top = null; this.count = 0; }
public Node(object data) { this.data = data; this.next = null; }
public void delete(T val) { Node<T> node = findNode(root, val); if (node == null) return; else if (node.isLeaf()) { if (node == root) root = null; else if (node.Parent.Right == node) node.Parent.Right = null; else node.Parent.Left = null; } else if (node.hasOneChild()) { if (node == root) { if (node.Left != null) { root = node.Left; } else { root = node.Right; } root.Parent = null; } else if (node.Parent.Left == node) { if (node.Left != null) { node.Parent.Left = node.Left; node.Left.Parent = node.Parent; } else { node.Parent.Left = node.Right; node.Right.Parent = node.Parent; } } else { if (node.Left != null) { node.Parent.Right = node.Left; node.Left.Parent = node.Parent; } else { node.Parent.Right = node.Right; node.Right.Parent = node.Parent; } } } else if (node.hasTwoChild()) { Node<T> successor = node.Right; while (successor.Left != null) successor = successor.Left; delete(successor.val); successor.Right = node.Right; successor.Left = node.Left; if (node.Left != null) node.Left.Parent = successor; if (node.Right != null) node.Right.Parent = successor; successor.Parent = node.Parent; if (node == root) root = successor; else if (node.Parent.Right == node) node.Parent.Right = successor; else if(node.Parent.Left==node) node.Parent.Left = successor; } }