示例#1
0
文件: avlTree.cs 项目: kepon2/cP
        private Nodetree RotateRL(Nodetree parent)
        {
            Nodetree pivot = parent.right;

            parent.right = RotateLL(pivot);
            return(RotateRR(parent));
        }
示例#2
0
文件: avlTree.cs 项目: kepon2/cP
        private Nodetree Find(string vacancy, Nodetree current)
        {
            Nodetree target = new Nodetree(vacancy, null, null);

            if (target < current)
            {
                if (vacancy == current.vacancy)
                {
                    return(current);
                }
                else if (current.left != null)
                {
                    return(Find(vacancy, current.left));
                }
                else
                {
                    return(current);
                }
            }
            else
            {
                if (vacancy == current.vacancy)
                {
                    return(current);
                }
                else if (current.right != null)
                {
                    return(Find(vacancy, current.right));
                }
                else
                {
                    return(current);
                }
            }
        }
示例#3
0
文件: avlTree.cs 项目: kepon2/cP
        private Nodetree RotateLR(Nodetree parent)
        {
            Nodetree pivot = parent.left;

            parent.left = RotateRR(pivot);
            return(RotateLL(parent));
        }
示例#4
0
文件: avlTree.cs 项目: kepon2/cP
        private Nodetree balance_tree(Nodetree current)
        {
            int b_factor = balance_factor(current);

            if (b_factor > 1)
            {
                if (balance_factor(current.left) > 0)
                {
                    current = RotateLL(current);
                }
                else
                {
                    current = RotateLR(current);
                }
            }
            else if (b_factor < -1)
            {
                if (balance_factor(current.right) > 0)
                {
                    current = RotateRL(current);
                }
                else
                {
                    current = RotateRR(current);
                }
            }
            return(current);
        }
示例#5
0
文件: avlTree.cs 项目: kepon2/cP
        private Nodetree RotateLL(Nodetree parent)
        {
            Nodetree pivot = parent.left;

            parent.left = pivot.right;
            pivot.right = parent;
            return(pivot);
        }
示例#6
0
文件: avlTree.cs 项目: kepon2/cP
        private int balance_factor(Nodetree current)
        {
            int l        = getHeight(current.left);
            int r        = getHeight(current.right);
            int b_factor = l - r;

            return(b_factor);
        }
示例#7
0
文件: avlTree.cs 项目: kepon2/cP
 public void getReport(Nodetree current, reportClass rC, payMap pM)
 {
     if (current != null)
     {
         getReport(current.left, rC, pM);
         Tuple <int, pMap.info, int, string> finded = pM.findInHashTable(current.vacancy);
         rC.pushArray(current.FIO, finded.Item2.field1, null, null);
         getReport(current.right, rC, pM);
     }
 }
示例#8
0
文件: avlTree.cs 项目: kepon2/cP
        public void Add(string vacancy, string FIO, string unit)
        {
            Nodetree newItem = new Nodetree(vacancy, FIO, unit);

            if (root == null)
            {
                root = newItem;
            }
            else
            {
                root = RecursiveInsert(root, newItem);
            }
        }
示例#9
0
文件: avlTree.cs 项目: kepon2/cP
        private int getHeight(Nodetree current)
        {
            int height = 0;

            if (current != null)
            {
                int l = getHeight(current.left);
                int r = getHeight(current.right);
                int m = max(l, r);
                height = m + 1;
            }
            return(height);
        }
示例#10
0
文件: avlTree.cs 项目: kepon2/cP
        public Nodetree Find(string vacancy)
        {
            Nodetree search = Find(vacancy, root);

            if (search.vacancy == vacancy)//исправить
            {
                return(search);
            }
            else
            {
                Nodetree target = new Nodetree(null, null, null);
                return(target);
            }
        }
示例#11
0
文件: avlTree.cs 项目: kepon2/cP
 private Nodetree RecursiveInsert(Nodetree current, Nodetree n)
 {
     if (current == null)
     {
         current = n;
         return(current);
     }
     else if (n < current)
     {
         current.left = RecursiveInsert(current.left, n);
         current      = balance_tree(current);
     }
     else if (n > current)
     {
         current.right = RecursiveInsert(current.right, n);
         current       = balance_tree(current);
     }
     return(current);
 }
示例#12
0
文件: avlTree.cs 项目: kepon2/cP
 public void clear()
 {
     root = null;
 }
示例#13
0
文件: avlTree.cs 项目: kepon2/cP
        private Nodetree Delete(Nodetree current, string vacancy, string FIO, string unit)
        {
            Nodetree target = new Nodetree(vacancy, FIO, unit);
            Nodetree parent;

            if (current == null)
            {
                return(null);
            }
            else
            {
                //left subtree
                if (target < current)
                {
                    current.left = Delete(current.left, vacancy, FIO, unit);
                    if (balance_factor(current) == -2)//here
                    {
                        if (balance_factor(current.right) <= 0)
                        {
                            current = RotateRR(current);
                        }
                        else
                        {
                            current = RotateRL(current);
                        }
                    }
                }
                //right subtree
                else if (target > current)
                {
                    current.right = Delete(current.right, vacancy, FIO, unit);
                    if (balance_factor(current) == 2)
                    {
                        if (balance_factor(current.left) >= 0)
                        {
                            current = RotateLL(current);
                        }
                        else
                        {
                            current = RotateLR(current);
                        }
                    }
                }
                //if target is found
                else
                {
                    if (current.right != null)
                    {
                        //delete its inorder successor
                        parent = current.right;
                        while (parent.left != null)
                        {
                            parent = parent.left;
                        }
                        current.vacancy = parent.vacancy;
                        current.FIO     = parent.FIO;
                        current.unit    = parent.unit;
                        current.right   = Delete(current.right, parent.vacancy, parent.FIO, parent.unit);
                        if (balance_factor(current) == 2)//rebalancing
                        {
                            if (balance_factor(current.left) >= 0)
                            {
                                current = RotateLL(current);
                            }
                            else
                            {
                                current = RotateLR(current);
                            }
                        }
                    }
                    else
                    {   //if current.left != null
                        return(current.left);
                    }
                }
            }
            return(current);
        }
示例#14
0
文件: avlTree.cs 项目: kepon2/cP
 public void Delete(string vacancy, string FIO, string unit)
 {//and here
     root = Delete(root, vacancy, FIO, unit);
 }