Beispiel #1
0
 public Graph(string name)
 {
     using (StreamReader file = new StreamReader (name))
     {
         graph = new Node (Graph.readInputFile (name));
     }
 }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
        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;
            }
        }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
 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);
         }
     }
 }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 //поиск листьев
 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;
 }
Beispiel #8
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);
     }
 }
Beispiel #9
0
 public void setGraph(int[, ] adjMatrix)
 {
     graph = new Node (adjMatrix);
 }
Beispiel #10
0
 public Graph(int[ , ] adjMatrix)
 {
     graph = new Node (adjMatrix);
 }
Beispiel #11
0
 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;
     }
 }
Beispiel #12
0
 public Node(char nodeInf)
 {
     inf = nodeInf;
     left = null;
     right = null;
 }
Beispiel #13
0
 public static void Preorder(Node r)
 {
     if (r != null)
     {
         Console.Write ("{0}", r.inf);
         Preorder (r.left);
         Preorder (r.right);
     }
 }
Beispiel #14
0
            //            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);
                }
            }
Beispiel #15
0
 public BinaryTree()
 {
     tree = null;
 }
Beispiel #16
0
        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);
            }
        }
Beispiel #17
0
 public Node(Subscriber subscriber)
 {
     this.subscriber = subscriber;
     this.left = null;
     this.right = null;
     this.children = 1;
 }
Beispiel #18
0
        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;
        }
Beispiel #19
0
 public BinaryTree()
 {
     this.root = null;
 }
Beispiel #20
0
 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);
     }
 }
Beispiel #21
0
        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);
            }
        }
Beispiel #22
0
 private BinaryTree(Node r)
 {
     tree = r;
 }
Beispiel #23
0
        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);
        }
Beispiel #24
0
 //создание узла
 public Node(object nodeInf)
 {
     inf = nodeInf;
     left = null;
     right = null;
 }
Beispiel #25
0
 private void InvalidateLeastRecentlyUsed()
 {
     _cache.Remove(_tail.Key);
     _tail.Previous.Next = null;
     _tail = _tail.Previous;
 }