public Graph(string name) { using (StreamReader file = new StreamReader (name)) { graph = new Node (Graph.readInputFile (name)); } }
private void FlagMostRecentlyUsed(Node node) { if (node.Next == null && node.Previous == null) { node.Next = _head; _head.Previous = node; if (_head.Next == null) { _tail = _head; } _head = node; } else if (node.Next == null && node.Previous != null) { node.Previous.Next = null; _tail = node.Previous; node.Next = _head; _head.Previous = node; _head = node; } else if (node.Next != null && node.Previous != null) { node.Previous.Next = node.Next; node.Next.Previous = node.Previous; node.Next = _head; _head.Previous = node; _head = node; } }
public void Count(ref Node node) { node.children = 1; if (node.left != null) { node.children += node.left.children; } if (node.right != null) { node.children += node.right.children; } }
public int Walk(Node node) { if (node == null) { return 0; } if (node.left == null && node.right == null ) { return (int)node.inf; } else { return Walk(node.left) + Walk(node.right); } }
private void Add(ref Node node, Subscriber newCome) { if (node == null) { node = new Node(newCome); } else { node.children++; if (node.subscriber.Id > newCome.Id) { Add(ref node.left, newCome); } else { Add(ref node.right, newCome); } } }
public void set(int key, int value) { if (_cache.ContainsKey(key)) { FlagMostRecentlyUsed(_cache[key]); } if (_cache.Count >= _capacity) InvalidateLeastRecentlyUsed(); var newNode = new Node(key, value); if (_head == null) { _head = newNode; _tail = _head; } else { FlagMostRecentlyUsed(newNode); } _cache.Add(key, newNode); }
//поиск листьев public static object Sheet(Node x) { if (x != null) { if (x.left != null) return Sheet (x.left); else if (x.right != null) return Sheet (x.right); else return 0; } return 0; }
//добавление узла согласно определению бин. дерева public static void Add(ref Node r, object nodeInf) { if (r == null) { r = new Node (nodeInf); } else { if (((IComparable)(r.inf)).CompareTo(nodeInf) > 0) Add (ref r.left, nodeInf); else Add (ref r.right, nodeInf); } }
public void setGraph(int[, ] adjMatrix) { graph = new Node (adjMatrix); }
public Graph(int[ , ] adjMatrix) { graph = new Node (adjMatrix); }
private int CalcChildren(ref Node node) { if (node != null) { node.children = CalcChildren(ref node.left) + CalcChildren(ref node.right) + 1; return node.children; } else { return 0; } }
public Node(char nodeInf) { inf = nodeInf; left = null; right = null; }
public static void Preorder(Node r) { if (r != null) { Console.Write ("{0}", r.inf); Preorder (r.left); Preorder (r.right); } }
// public Node (char nodeInf, ref Node aParent) // { // inf = nodeInf; // left = null; // right = null; // //parent = aParent; // } // public Node () // { // inf = null; // left = null; // right = null; // } // public Node (ref Node aParent) // { // inf = null; // left = null; // right = null; // //parent = aParent; // } //добавление узла согласно определению бин. дерева // public static void Add(ref Node r, object nodeInf) // { // if (r == null) // { // r = new Node (nodeInf); // } // else // { // if (((IComparable)(r.inf)).CompareTo(nodeInf) > 0) // Add (ref r.left, nodeInf); // else // Add (ref r.right, nodeInf); // } // } public static void Add(ref Node r, char n, ref bool flag) { if (r == null) { r = new Node(n); flag = true; } else { if (!isOp(r.inf)) { return; } Add(ref r.left, n,ref flag); if(!flag) Add(ref r.right, n, ref flag); } }
public BinaryTree() { tree = null; }
private void GetSortedData(ref Node node, ref List<Subscriber> list) { if (node != null) { GetSortedData(ref node.left, ref list); list.Add(node.subscriber); GetSortedData(ref node.right, ref list); } }
public Node(Subscriber subscriber) { this.subscriber = subscriber; this.left = null; this.right = null; this.children = 1; }
private void RotationRight(ref Node node) { Node tmp = node.left; node.left = tmp.right; tmp.right = node; Count(ref node); Count(ref tmp); node = tmp; }
public BinaryTree() { this.root = null; }
private void Part(ref Node node, int index) { int left = (node.left == null) ? 0 : node.left.children; if (left > index) { Part(ref node.left, index); RotationRight(ref node); } if (left < index) { Part(ref node.right, index - left - 1); RotationLeft(ref node); } }
private void IsBalanced(ref Node node, ref bool answer) { if (node != null) { int left = (node.left != null) ? node.left.children : 0; int right = (node.right != null) ? node.right.children : 0; if (Math.Abs(left - right) > 1) { answer = false; } IsBalanced(ref node.left, ref answer); IsBalanced(ref node.right, ref answer); } }
private BinaryTree(Node r) { tree = r; }
private void Balancer(ref Node node) { if (node == null || node.children == 1) return; //Console.WriteLine(node == null); Part(ref node, node.children / 2); Balancer(ref node.left); Balancer(ref node.right); }
//создание узла public Node(object nodeInf) { inf = nodeInf; left = null; right = null; }
private void InvalidateLeastRecentlyUsed() { _cache.Remove(_tail.Key); _tail.Previous.Next = null; _tail = _tail.Previous; }