예제 #1
0
파일: Search.cs 프로젝트: SaikoVlad/work
        public static Toy FindToy(IJsfTree tree, SearchParam param, double paramValue)
        {
            foreach (var toy in tree)
            {
                if (param == SearchParam.PRICE)
                {
                    if (paramValue == toy.GetPrice())
                    {
                        return(toy);
                    }
                }
                else if (param == SearchParam.SIZE)
                {
                    if (paramValue == toy.GetSize())
                    {
                        return(toy);
                    }
                }
                else
                {
                    if (paramValue == toy.GetWeight())
                    {
                        return(toy);
                    }
                }
            }

            return(null);
        }
예제 #2
0
        public static void Insert(IJsfTree tree)
        {
            Toy temp;
            int j;

            for (int i = 0; i < tree.GetSizeOfTree() - 1; i++)
            {
                if (tree.GetToy(i).CompareTo(tree.GetToy(i + 1)) > 0)
                {
                    temp = tree.GetToy(i + 1);
                    tree.ChangeToy(tree.GetToy(i), i + 1);
                    j = i;
                    while (j > 0 && tree.GetToy(j - 1).CompareTo(temp) > 0)
                    {
                        tree.ChangeToy(tree.GetToy(j - 1), j);
                        j--;
                    }

                    tree.ChangeToy(temp, j);
                }
            }
        }
예제 #3
0
        public static void Bubble(IJsfTree tree)
        {
            bool sorted = true;

            for (int i = tree.GetSizeOfTree(); i > 0; i--)
            {
                for (int j = 0; j < i - 1; j++)
                {
                    if (tree.GetToy(j).CompareTo(tree.GetToy(j + 1)) > 0)
                    {
                        Toy tmp = tree.GetToy(j);
                        tree.ChangeToy(tree.GetToy(j + 1), j);
                        tree.ChangeToy(tmp, j + 1);
                        sorted = false;
                    }

                    if (sorted)
                    {
                        return;
                    }
                }
            }
        }