Exemple #1
0
        private void buttonSortStart_Click(object sender, EventArgs e)
        {
            if (working)
            {
                return;
            }
            if (string.IsNullOrEmpty(chooseDirPath))
            {
                MessageBox.Show("请先选择目录");
                return;
            }

            if (radioButtonBubbleSort.Checked)
            {
                sortAlgorithm = SortAlgorithm.BubbleSort;
            }
            else if (radioButtonCountingSort.Checked)
            {
                sortAlgorithm = SortAlgorithm.CountingSort;
            }

            working = true;

            Log("开启子线程执行");

            ThreadPool.QueueUserWorkItem(SortFiles, chooseDirPath);
        }
        public static ISort <Data, SortingResult> GetAlgorithm(SortAlgorithm sortAlgorithm, SortMode sortMode)
        {
            Func <Data, Data, int>      compareFunc  = CompareMethodFactory.GetMethod(sortMode);
            ISort <Data, SortingResult> sortVariable = null;

            switch (sortAlgorithm)
            {
            case SortAlgorithm.BubbleSort:
                sortVariable = new BubbleSort(compareFunc);
                break;

            case SortAlgorithm.SelectionSort:
                sortVariable = new SelectionSort(compareFunc);
                break;


            case SortAlgorithm.InsertionSort:
                sortVariable = new InsertionSort(compareFunc);
                break;

            case SortAlgorithm.QuickSort:
                sortVariable = new QuickSort(compareFunc);
                break;

            case SortAlgorithm.BubbleWithCheckOfState:
                sortVariable = new BubbleSortWithCheckOfState(compareFunc);
                break;

            default:
                throw new ArgumentException("Algorithm not found!!!");
            }

            return(sortVariable);
        }
Exemple #3
0
        void bProcess_Click(object sender, EventArgs e)
        {
            // cancel whatever task is in progress
            if (currentTask != null)
            {
                runAfterCancel = true;
                worker.CancelAsync();
                currentTask.CancelAsync();
                return;
            }

            SortAlgorithm algo          = (SortAlgorithm)cAlgorithm.SelectedIndex;
            SortOrder     order         = (SortOrder)cOrder.SelectedIndex;
            SortMetric    metric        = (SortMetric)cMetric.SelectedIndex;
            SamplingMode  sampling      = (SamplingMode)cSampling.SelectedIndex;
            int           segmentWidth  = (int)nSegmentWidth.Value;
            int           segmentHeight = (int)nSegmentHeight.Value;
            double        threshold     = tbThreshold.Value / 100d;

            pbProgress.Value = 0;
            SetProgressVisible(true);

            currentTask = new SortingTask(algo,
                                          order,
                                          metric,
                                          sampling,
                                          segmentWidth,
                                          segmentHeight,
                                          (Bitmap)originalImage.Clone(),
                                          threshold);
            currentTask.ProgressChanged += (o, args) => worker.ReportProgress(args.ProgressPercentage);

            worker.RunWorkerAsync();
        }
Exemple #4
0
        /// <summary>
        /// Получает понятное имя элемента перечислителя.
        /// </summary>
        public static string GetName(this SortAlgorithm sortAlgorithm)
        {
            switch (sortAlgorithm)
            {
            case SortAlgorithm.Bubble:
                return("Пузырьковая сортировка");

            case SortAlgorithm.Quick:
                return("Быстрая сортировка");

            case SortAlgorithm.Selection:
                return("Cортировка выбором");

            case SortAlgorithm.Heap:
                return("Пирамидальная сортировка");

            case SortAlgorithm.Insert:
                return("Сортировка вставками");

            case SortAlgorithm.Shell:
                return("Сортировка Шелла");

            default:
                return(null);
            }
        }
Exemple #5
0
 public GUI(SortAlgorithm s)
 {
     theProblem = ProblemFactory.createActualProblem();
     theAlgorithm = s;
     InitializeComponent();
     initializeGUI();
 }
        public static StatisticsSummary CalculateSummary(double[] values)
        {
            if (values == null || values.Length == 0)
            {
                return(new StatisticsSummary());
            }

            var length = values.Length;

            var sortedValues = SortAlgorithm.MergeSort <double>(values, (a, b) => a.CompareTo(b));

            var result = new StatisticsSummary();

            result.Min = sortedValues.First();

            result.Max = sortedValues.Last();

            result.FirstQuartile = sortedValues[length / 4];

            result.Median = sortedValues[length / 2];

            result.ThirdQuartile = sortedValues[length * 3 / 4];

            result.Mean = Msh.Statistics.Statistics.CalculateMean(values);

            return(result);
        }
Exemple #7
0
 public GUI(SortAlgorithm s)
 {
     theProblem   = ProblemFactory.createActualProblem();
     theAlgorithm = s;
     InitializeComponent();
     initializeGUI();
 }
        public Dictionary <int, int> Compare(ImageDescriptors referenceImage, ImageDescriptors targetImage, double threshold)
        {
            Dictionary <int, int> result = new Dictionary <int, int>();

            for (int i = 0; i < targetImage.Count; i++)
            {
                IndexValue <double>[] temp = new IndexValue <double> [referenceImage.Count];

                for (int j = 0; j < referenceImage.Count; j++)
                {
                    temp[j] = new IndexValue <double>(j, Descriptor.CalculateAngle(referenceImage[j], targetImage[i]));
                }

                SortAlgorithm.Heapsort <IndexValue <double> >(ref temp, SortDirection.Descending);

                if (temp[0].Value.Equals(double.NaN))
                {
                    throw new NotImplementedException();
                }

                if (temp[0].Value / temp[1].Value < threshold)
                {
                    result.Add(i, temp[0].Index);
                }
            }

            return(result);
        }
Exemple #9
0
        private void Test()
        {
            System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew();

            Random r = new Random();

            int[] array10k = Enumerable.Repeat(0, 10000).Select(i => r.Next()).ToArray();

            SortAlgorithm.Heapsort <int>(array10k, (p1, p2) => p1.CompareTo(p2));

            watch.Stop();
            Debug.WriteLine($"Heapsort, {array10k.Length}, {watch.ElapsedMilliseconds / 1000.0}");
            watch.Restart();

            SortAlgorithm.MergeSort <int>(array10k, (p1, p2) => p1.CompareTo(p2));

            watch.Stop();
            Debug.WriteLine($"MergeSort, {array10k.Length}, {watch.ElapsedMilliseconds / 1000.0}");
            watch.Restart();

            SortAlgorithm.QuickSort <int>(array10k, (p1, p2) => p1.CompareTo(p2));

            watch.Stop();
            Debug.WriteLine($"QuickSort, {array10k.Length}, {watch.ElapsedMilliseconds / 1000.0}");
            watch.Restart();

            SortAlgorithm.BubbleSort <int>(array10k, (p1, p2) => p1.CompareTo(p2));

            watch.Stop();
            Debug.WriteLine($"BubbleSort, {array10k.Length}, {watch.ElapsedMilliseconds / 1000.0}");
            watch.Restart();
        }
Exemple #10
0
        public List <EscolaRank> Rankeia()
        {
            List <EscolaRank> escolasRankeadas = GeraListaDeEscolasVM();

            List <DadosSeries>     dadosSeries     = new List <DadosSeries>();
            List <ProvasSegmentos> provasSegmentos = new List <ProvasSegmentos>();

            //Começa a normalização dos objetos aqui.
            foreach (EscolaRank escola in escolasRankeadas)
            {
                foreach (DadosSeries dadosSerie in escola.DadosSeries)
                {
                    dadosSeries.Add(dadosSerie);
                }
                foreach (ProvasSegmentos provasSegmento in escola.ProvasSegmentos)
                {
                    provasSegmentos.Add(provasSegmento);
                }
            }

            foreach (EscolaRank escola in escolasRankeadas)
            {
                foreach (DadosSeries dadosSerie in escola.DadosSeries)
                {
                    dadosSerie.TaxaAprovacao = Helpers.ValorNormalizado(dadosSerie.TaxaAprovacao, dadosSeries);
                }

                //List das provas da escola
                List <double> listProvaBrasil = new List <double>();
                List <double> listIdeb        = new List <double>();
                List <double> listSpaece      = new List <double>();
                List <double> listReprovacao  = new List <double>();

                foreach (ProvasSegmentos provaSegmento in escola.ProvasSegmentos)
                {
                    listProvaBrasil.Add(provaSegmento.ProvaBrasil);
                    listIdeb.Add(provaSegmento.Ideb);
                    listSpaece.Add(provaSegmento.Spaece);
                }

                foreach (DadosSeries dadosSerie in dadosSeries)
                {
                    listReprovacao.Add(dadosSerie.TaxaAprovacao);
                }


                for (int i = 0; i < escola.ProvasSegmentos.Count; i++)
                {
                    escola.ProvasSegmentos[i].ProvaBrasil = Helpers.ValorNormalizado(escola.ProvasSegmentos[i].ProvaBrasil, escola.ProvasSegmentos, "ProvaBrasil");
                    escola.ProvasSegmentos[i].Ideb        = Helpers.ValorNormalizado(escola.ProvasSegmentos[i].Ideb, escola.ProvasSegmentos, "Ideb");
                    escola.ProvasSegmentos[i].Spaece      = Helpers.ValorNormalizado(escola.ProvasSegmentos[i].Spaece, escola.ProvasSegmentos, "Spaece");
                    //acaba aqui a normalização

                    escola.Nota = (((Helpers.Media(listProvaBrasil) + Helpers.Media(listIdeb) + Helpers.Media(listSpaece)) / 3) * 0.4) + (Helpers.Media(listReprovacao) * 0.6);
                }
            }

            return(SortAlgorithm.QuickSortModificado(escolasRankeadas));
        }
        public int FindMatch(ImageDescriptors image, double threshold)
        {
            List <IndexValue <double> > values = CalculateSimilariry(image, threshold);

            SortAlgorithm.Heapsort <IndexValue <double> >(ref values, SortDirection.Ascending);

            return(values[0].Index);
        }
        public static Point[] HosseinSorter(Point[] array)
        {
            Boundary boundary = GetBoundary(array, 5);

            var sfc = SpaceFillingCurves.Hossein(Moves.North, Moves.East);

            return(SortAlgorithm.MergeSort <Point>(array, (p1, p2) => sfc.ComparePoints(p1, p2, boundary)));
        }
        public void StartMethod()
        {
            var fArr = DataGenerator.Generate(CountOfElements);

            var sortingResult = SortAlgorithm.Sort(fArr);

            ResultPrinter.Write(PathToFile, sortingResult);
        }
Exemple #14
0
        private void mergeSortMenuClicked(object sender, EventArgs e)
        {
            clearOldStuff();
            NumberSwapListener old = theAlgorithm.getNumberSwapListener();

            theAlgorithm = new MergeSort();
            theAlgorithm.setNumberSwapListener(old);
            initializeGUI();
        }
Exemple #15
0
 static void BenchmarkSort()
 {
     SortAlgorithm.BenchmarkSort(5, (int)Math.Pow(2, 10));
     SortAlgorithm.BenchmarkSort(5, (int)Math.Pow(2, 11));
     SortAlgorithm.BenchmarkSort(5, (int)Math.Pow(2, 12));
     SortAlgorithm.BenchmarkSort(5, (int)Math.Pow(2, 13));
     SortAlgorithm.BenchmarkSort(5, (int)Math.Pow(2, 14));
     SortAlgorithm.BenchmarkSort(5, (int)Math.Pow(2, 15));
 }
Exemple #16
0
        public void SwapTest()
        {
            int           a         = 1;
            int           b         = 2;
            SortAlgorithm algorithm = new SortAlgorithm();

            algorithm.Swap(ref a, ref b);
            Assert.AreEqual(2, a);
            Assert.AreEqual(1, b);
        }
Exemple #17
0
        public void BubbleSortTest()
        {
            var expected = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            var actual   = new int[] { 8, 5, 3, 2, 4, 1, 6, 7 };

            Console.WriteLine("Before sort: " + string.Join <int>(",", actual));
            SortAlgorithm.BubbleSort <int>(actual, (a, b) => a < b);
            Console.WriteLine("After sort: " + string.Join <int>(",", actual));
            CollectionAssert.AreEqual(expected, actual);
        }
Exemple #18
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello world!");
            // StackSample ss = new StackSample();
            // ss.Conversion(16);
            // char[] brackets = new char[] { '(', '[', ']', ')' };
            // bool match = ss.MatchBracket(brackets);
            // Console.WriteLine("\"{0}\"匹配结果:{1}", new String(brackets), match);
            // ss.EvaluteExpression();
            // QueueSample qs = new QueueSample();
            // qs.Plalindrome();
            // Strings ss = new Strings(new char[] { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' });
            // Console.WriteLine(ss);
            // ss = ss.Insert(0,new Strings(new char[]{'k','h','a','d','r','o','n',' '}));
            // Console.WriteLine(ss);

            // TreeNode<string> root = new TreeNode<string>("根节点O");

            // TreeNode<string> n1 = new TreeNode<string>("第一层,左结点A");
            // TreeNode<string> n1_1 = new TreeNode<string>("第二层 左结点C");
            // n1.LeftChild = n1_1;
            // TreeNode<string> n1_2 = new TreeNode<string>("第二层 右结点D");
            // n1.RightChild = n1_2;

            // TreeNode<string> n2 = new TreeNode<string>("第一层 右结点B");
            // TreeNode<string> n2_1 = new TreeNode<string>("第二层 左结点E");
            // n2.LeftChild = n2_1;
            // TreeNode<string> n2_2 = new TreeNode<string>("第二层 右结点F");
            // n2.RightChild = n2_2;

            // root.LeftChild = n1;
            // root.RightChild = n2;

            // BiTree<string> bt = new BiTree<string>();
            // Console.WriteLine("=====");
            // Console.WriteLine("前序遍历:");
            // bt.PreOrder(root);
            // Console.WriteLine("=====");
            // Console.WriteLine("中序遍历:");
            // bt.InOrder(root);
            // Console.WriteLine("=====");
            // Console.WriteLine("后序遍历:");
            // bt.PostOrder(root);
            // Console.WriteLine("=====");
            // Console.WriteLine("层序遍历:");
            // bt.LevelOrder(root);

            //快排
            int[] arr = { 0, 6, 9, 4, 3, 5, 7 };
            Console.WriteLine("排序前");
            SortAlgorithm.Print(arr);
            SortAlgorithm.QuickSort(arr, 0, arr.Length - 1);
            Console.WriteLine("排序后");
            SortAlgorithm.Print(arr);
        }
Exemple #19
0
 static async Task Main(string[] args)
 {
     try
     {
         SortAlgorithm.Run();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
        public static Point[] NOrderingSorter(Point[] array)
        {
            Boundary boundary = GetBoundary(array, 5);

            var sfc = SpaceFillingCurves.NOrdering(Moves.North, Moves.SouthEast);

            //return SortAlgorithm.Heapsort<Point>(array, (p1, p2) => NOrderingComparer(p1, p2, boundary));
            //return SortAlgorithm.MergeSort<Point>(array, (p1, p2) => NOrderingComparer(p1, p2, boundary));
            //IRI.Msh.DataStructure.SortAlgorithm.QuickSort<Point>(array, (p1, p2) => HilbertComparer(p1, p2, boundary));
            //return array;

            return(SortAlgorithm.MergeSort <Point>(array, (p1, p2) => sfc.ComparePoints(p1, p2, boundary)));
        }
        private void LoadFolder(string path)
        {
            var list = Directory.GetFiles(path).ToList();

            list.Sort((x, y) => SortAlgorithm.ComparePath(x, y));
            ImagePanel.Children.Clear();
            list.ForEach(x => {
                if (x.EndsWith(".zip"))
                {
                    ImagePanel.Children.Add(new ZipViewerElements(x));
                }
            });
        }
Exemple #22
0
    public void Main()
    {
        Stopwatch stopwatch = new Stopwatch();

        int[] ar = new int[] { 100, 1000, 2000, 3000, 4000, 9, 0 };
        Console.WriteLine("Original first array elements ");
        foreach (int i in ar)
        {
            Console.Write(i + ",");
        }
        Console.WriteLine();
        // stopwatch.Start();

        Task sort = SortAlgorithm <int> .MergeSortAsync(ar);

        // stopwatch.Stop();
        // stopwatch.stop();
        Console.WriteLine("Sorted first array ");
        foreach (int i in ar)
        {
            Console.Write(i + ",");
        }
        Console.WriteLine();
        sort.Wait();

        // foreach (int i in ar)
        //  Console.WriteLine(i);
        //
        // Console.WriteLine();

        ar = new int[] { 93232, 12121, 712, 221, 212, 12 };
        Console.WriteLine("Original second array elements ");
        foreach (int i in ar)
        {
            Console.Write(i + ",");
        }
        Console.WriteLine();
        // stopwatch.start();
        stopwatch.Start();
        sort = SortAlgorithm <int> .MergeSortAsync(ar);

        sort.Wait();
        stopwatch.Stop();
        Console.WriteLine("Sorted second array ");
        foreach (int i in ar)
        {
            Console.Write(i + ",");
        }
        Console.WriteLine();
        Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
    }
Exemple #23
0
        public void MergeArrayTest()
        {
            SortAlgorithm simple = new SortAlgorithm();

            int[] a = { 1, 4, 7 };
            int[] b = { 2, 3, 5, 6, 8 };
            int[] c = new int[a.Length + b.Length];
            simple.MergeArray(a, a.Length, b, b.Length, c);

            for (int i = 0; i < c.Length; i++)
            {
                Assert.AreEqual(i + 1, c[i]);
            }
        }
        private void MangaCrawler_Loaded(object sender, RoutedEventArgs e)
        {
            Task.Run(() =>
            {
                string base_url = "https://mangashow.me/bbs/page.php?hid=manga_list&page=";

                int max    = MangashowmeParser.ParseMaxPage(NetCommon.DownloadString(base_url));
                var result = EmiliaJob.Instance.AddJob(Enumerable.Range(0, max).Select(x => base_url + x).ToList(),
                                                       (count) =>
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                   delegate
                    {
                        ProgressText.Text = $"가져오는 중...[{count}/{max}]";
                    }));
                });

                List <Tuple <string, string> > articles = new List <Tuple <string, string> >();

                for (int i = 0; i < result.Count; i++)
                {
                    articles.AddRange(MangashowmeParser.ParseIndex(result[i]));
                }

                foreach (var article in articles)
                {
                    mangas.Add(Tuple.Create(article.Item1, article.Item2, article.Item2.Split('=').Last().Trim()));
                }

                mangas.Sort((x, y) => SortAlgorithm.ComparePath(x.Item3, y.Item3));

                foreach (var manga in mangas)
                {
                    elems.Add(new Lazy <MangaCrawlerElements>(() =>
                    {
                        return(new MangaCrawlerElements(manga.Item1, manga.Item2, manga.Item3));
                    }));
                }

                Application.Current.Dispatcher.BeginInvoke(new Action(
                                                               delegate
                {
                    CollectStatusPanel.Visibility = Visibility.Collapsed;

                    max_page = (mangas.Count - 1) / 36;
                    set_page_segment(0);
                    show_page(0);
                }));
            });
        }
Exemple #25
0
        public SortingTask(SortAlgorithm algorithm, SortOrder order, SortMetric metric, SamplingMode sampling,
                           int segmentWidth, int segmentHeight, Bitmap originalImage, double threshold)
        {
            Algorithm      = algorithm;
            Order          = order;
            Metric         = metric;
            Sampling       = sampling;
            SegmentWidth   = segmentWidth;
            SegmentHeight  = segmentHeight;
            OriginalImage  = originalImage;
            Threshold      = threshold;
            segmentRows    = OriginalImage.Height / SegmentHeight;
            segmentColumns = OriginalImage.Width / SegmentWidth;

            switch (Algorithm)
            {
            case SortAlgorithm.WholeImage:
                segments    = new Segment[1][];
                segments[0] = new Segment[segmentRows * segmentColumns];
                break;

            case SortAlgorithm.Column:
                segments = new Segment[segmentColumns][];
                for (int col = 0; col < segmentColumns; ++col)
                {
                    segments[col] = new Segment[segmentRows];
                }
                break;

            case SortAlgorithm.Row:
                segments = new Segment[segmentRows][];
                for (int row = 0; row < segmentRows; ++row)
                {
                    segments[row] = new Segment[segmentColumns];
                }
                break;

            case SortAlgorithm.Segment:
                segments = new Segment[segmentRows * segmentColumns][];
                for (int i = 0; i < segments.Length; ++i)
                {
                    segments[i] = new Segment[segmentWidth * segmentHeight];
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #26
0
        /// <summary>
        /// Chen and Guevara 77
        /// </summary>
        /// <param name="numberOfPoints"></param>
        /// <returns></returns>
        public AttributedPointCollection SelectPointsBaesdOnCAG(int numberOfPoints)
        {
            int numberOfRow = this.NumberOfRows;

            int numberOfColumns = this.NumberOfColumns;

            IndexValue <double>[] significanceValues = new IndexValue <double> [numberOfRow * numberOfColumns];

            for (int i = 1; i < numberOfRow - 1; i++)
            {
                for (int j = 1; j < numberOfColumns - 1; j++)
                {
                    double first = CalculateSecondDifference(i, j, RasterDirection.EastWest);

                    double second = CalculateSecondDifference(i, j, RasterDirection.SouthNorth);

                    double third = CalculateSecondDifference(i, j, RasterDirection.NorthernWestSouthernEast);

                    double fourth = CalculateSecondDifference(i, j, RasterDirection.SouthernWestNorthernEast);

                    significanceValues[i * numberOfColumns + j] =
                        new IndexValue <double>(i * numberOfColumns + j, first + second + third + fourth);
                }
            }

            IndexValue <double>[] sortedSignificanceValues = SortAlgorithm.Heapsort <IndexValue <double> >(significanceValues, SortDirection.Ascending);

            AttributedPointCollection irregularPoints = new AttributedPointCollection();

            for (int i = 0; i < numberOfPoints; i++)
            {
                int row = (int)Math.Floor((double)sortedSignificanceValues[i].Index / numberOfColumns);

                int column = sortedSignificanceValues[i].Index % numberOfColumns;

                irregularPoints.Add(this.GetPoint(row, column));
            }

            //AddBorder
            irregularPoints.Add(this.LowerLeft);

            irregularPoints.Add(this.LoweRight);

            irregularPoints.Add(this.UpperLeft);

            irregularPoints.Add(this.UppeRight);

            return(irregularPoints);
        }
Exemple #27
0
        public void BubbledSortTest1()
        {
            int        number_count = 100;
            SimpleData data         = new SimpleData();
            var        array        = data.GetShuffleArray(number_count);

            SortAlgorithm algorithm = new SortAlgorithm();

            algorithm.BubbleSort(array);

            for (int i = 0; i < number_count; i++)
            {
                Assert.AreEqual(i, array[i]);
            }
        }
Exemple #28
0
        static void ProcessCarplates()
        {
            var plates = SwedishCarPlate.GenerateCarPlates((int)Math.Pow(2, 13));

            //var plates = SwedishCarPlate.GenerateCarPlates(5);

            //foreach (var item in plates)
            //{
            //    Console.WriteLine(item.CarPlate);
            //}

            //SortAlgorithm.BubbleSort<SwedishCarPlate>(plates, SwedishCarPlate.IsLettersOfALessThanB);
            //var letterSorted = (SwedishCarPlate[]) plates.Clone();

            //foreach (var item in letterSorted)
            //{
            //    Console.WriteLine(item.CarPlate);
            //}

            SortAlgorithm.BubbleSort <SwedishCarPlate>(plates, SwedishCarPlate.IsNumbersOfALessThanB);
            //var numberSorted = (SwedishCarPlate[])plates.Clone();

            //foreach (var item in numberSorted)
            //{
            //    Console.WriteLine(item.CarPlate);
            //}

            //Console.Write("Search Letters:");
            //var input = Console.ReadLine();

            //var position = SearchAlgorithms.BinarySearch<SwedishCarPlate>(letterSorted, new SwedishCarPlate { Letters = input }, SwedishCarPlate.CompareLetters);

            //Console.WriteLine("Position: " + position);

            Console.Write("Search Numbers:");
            var input = Console.ReadLine();

            var position = SearchAlgorithms.BinarySearch <SwedishCarPlate>(plates, new SwedishCarPlate {
                Numbers = input
            }, SwedishCarPlate.CompareNumbers);

            if (position > -1)
            {
                var similarPlates = SearchAlgorithms.RegionGrow <SwedishCarPlate>(plates, position, (a, b) => SwedishCarPlate.CompareNumbers(a, b) == 0);
                Console.WriteLine("Position: " + position + " -> " + plates[position].CarPlate);
                Console.WriteLine(String.Join(", ", similarPlates.Select(a => a.CarPlate)));
            }
        }
        public ZipArtistsElements(string path, ZipArtistsArtistModel model, int rating, bool offline = false)
        {
            InitializeComponent();

            ArtistTextBox.Text = model.ArtistName;
            Date.Text          = model.LastAccessDate;
            ArticleCount.Text  = model.ArticleData.Count + " Articles";

            this.path  = path;
            sub_folder = model.ArticleData.Select(x => x.Key).ToList();
            sub_folder.Sort((x, y) => SortAlgorithm.ComparePath(y, x));
            magics = model.ArticleData.Select(x => x.Value.Id).ToList();
            magics.Sort((x, y) => y.CompareTo(x));

            var tags = new Dictionary <string, int>();

            foreach (var v in model.ArticleData)
            {
                if (v.Value.Tags != null)
                {
                    foreach (var tag in v.Value.Tags)
                    {
                        if (tags.ContainsKey(tag))
                        {
                            tags[tag] += 1;
                        }
                        else
                        {
                            tags.Add(tag, 1);
                        }
                    }
                }
            }

            var tag_list = tags.ToList();

            tag_list.Sort((x, y) => y.Value.CompareTo(x.Value));

            ScoreTextBox.Text = string.Join("\r\n", tag_list.Select(x => x.Key));

            Loaded += ZipArtistsElements_Loaded;

            this.offline = offline;
            if (offline == true)
            {
                OpenFolder.IsEnabled = false;
            }
        }
        private void load()
        {
            var vm = DataContext as BookmarkPageDataGridViewModel;

            vm.Items.Clear();

            var ll = new List <BookmarkPageDataGridItemViewModel>();

            foreach (var artist in BookmarkModelManager.Instance.Model.artists)
            {
                if (artist.Item1 == classify_name)
                {
                    ll.Add(new BookmarkPageDataGridItemViewModel {
                        내용 = artist.Item2.content, 형 = "작가", 추가된날짜 = artist.Item2.stamp.ToString(), 경로 = artist.Item2.path, BIM = artist.Item2, 기타 = artist.Item2.etc
                    });
                }
            }
            foreach (var group in BookmarkModelManager.Instance.Model.groups)
            {
                if (group.Item1 == classify_name)
                {
                    ll.Add(new BookmarkPageDataGridItemViewModel {
                        내용 = group.Item2.content, 형 = "그룹", 추가된날짜 = group.Item2.stamp.ToString(), 경로 = group.Item2.path, BIM = group.Item2, 기타 = group.Item2.etc
                    });
                }
            }
            foreach (var article in BookmarkModelManager.Instance.Model.articles)
            {
                if (article.Item1 == classify_name)
                {
                    ll.Add(new BookmarkPageDataGridItemViewModel {
                        내용 = article.Item2.content + " - " + HitomiLegalize.GetMetadataFromMagic(article.Item2.content)?.Name, 형 = "작품", 추가된날짜 = article.Item2.stamp.ToString(), 경로 = article.Item2.path, BIM = article.Item2, 기타 = article.Item2.etc
                    });
                }
            }

            ll.Sort((x, y) => SortAlgorithm.ComparePath(y.추가된날짜, x.추가된날짜));

            for (int i = 0; i < ll.Count; i++)
            {
                ll[i].인덱스 = (i + 1).ToString();
            }

            foreach (var item in ll)
            {
                vm.Items.Add(item);
            }
        }
Exemple #31
0
        public void BucketSortTest()
        {
            int        number_count = 125;
            SimpleData data         = new SimpleData();
            var        array        = data.GetShuffleArray(number_count, start_from: 10);

            SortAlgorithm algorithm = new SortAlgorithm();

            algorithm.SimpleEditionBucketSort(array);
            ;

            for (int i = 0; i < number_count; i++)
            {
                Assert.AreEqual(i + 10, array[i]);
            }
        }
        /// <summary>
        /// Creates the sort algorithm implementation.
        /// </summary>
        /// <param name="algorithm">The algorithm.</param>
        /// <returns></returns>
        internal static ISortAlgorithm CreateSortAlgorithmImplementation(SortAlgorithm algorithm)
        {
            ISortAlgorithm toReturn = null;

            switch(algorithm)
            {
                case SortAlgorithm.SelectionSort:
                    toReturn = new SelectionSorter();
                    break;
                case SortAlgorithm.ShellSort:
                    toReturn = new ShellSorter();
                    break;
                case SortAlgorithm.QuickSort:
                    toReturn = new QuickSorter();
                    break;
            }

            return toReturn;
        }
Exemple #33
0
        private void cmdSort_Click(object sender, EventArgs e)
        {
            int speed = 100 - tbSpeed.Value;

            string alg1="";
            string alg2="";

            if(cboAlg1.SelectedItem!=null)
                alg1 = cboAlg1.SelectedItem.ToString();

            if(cboAlg2.SelectedItem!=null)
                alg2 = cboAlg2.SelectedItem.ToString();

            SortAlgorithm sa = new SortAlgorithm(array1, pnlSort1, true, txtOutputFolder.Text, speed, alg1);
            SortAlgorithm sa2 = new SortAlgorithm(array2, pnlSort2, true, txtOutputFolder.Text, speed, alg2);

            ThreadStart ts = delegate()
            {
                try
                {
                    switch (alg1)
                    {
                        case "BiDirectional Bubble Sort":
                            sa.BiDerectionalBubbleSort(array1);
                            break;
                        case "Bubble Sort":
                            sa.BubbleSort(array1);
                            break;
                        case "Bucket Sort":
                            sa.BucketSort(array1);
                            break;
                        case "Comb Sort":
                            sa.CombSort(array1);
                            break;
                        case "Cycle Sort":
                            sa.CycleSort(array1);
                            break;
                        case "Gnome Sort":
                            sa.GnomeSort(array1);
                            break;
                        case "Heap Sort":
                            sa.HeapSort(array1);
                            break;
                        case "Insertion Sort":
                            sa.InsertionSort(array1);
                            break;
                        case "Merge Sort":
                            sa.MergeSort(array1, 0, array1.Count - 1);
                            break;
                        case "Odd-Even Sort":
                            sa.OddEvenSort(array1);
                            break;
                        case "Quick Sort":
                            sa.QuickSort(array1, 0, array1.Count - 1);
                            break;
                        case "Quick Sort with Bubble Sort":
                            sa.QuickSortWithBubbleSort(array1, 0, array1.Count - 1);
                            break;
                        case "Selection Sort":
                            sa.SelectionSort(array1);
                            break;
                        case "Shell Sort":
                            sa.ShellSort(array1);
                            break;
                        case "Pigeon Hole Sort":
                            sa.PigeonHoleSort(array1);
                            break;
                    }
                    if(chkAnimation.Checked)
                        sa.CreateAnimation();
                    MessageBox.Show("Finish");
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message);
                }
            };

            ThreadStart ts2 = delegate()
            {
                try
                {
                    switch (alg2)
                    {
                        case "BiDirectional Bubble Sort":
                            sa2.BiDerectionalBubbleSort(array2);
                            break;
                        case "Bubble Sort":
                            sa2.BubbleSort(array2);
                            break;
                        case "Bucket Sort":
                            sa2.BucketSort(array2);
                            break;
                        case "Comb Sort":
                            sa2.CombSort(array2);
                            break;
                        case "Cycle Sort":
                            sa2.CycleSort(array2);
                            break;
                        case "Gnome Sort":
                            sa2.GnomeSort(array2);
                            break;
                        case "Heap Sort":
                            sa2.HeapSort(array2);
                            break;
                        case "Insertion Sort":
                            sa2.InsertionSort(array2);
                            break;
                        case "Merge Sort":
                            sa2.MergeSort(array2, 0, array2.Count - 1);
                            break;
                        case "Odd-Even Sort":
                            sa2.OddEvenSort(array2);
                            break;
                        case "Quick Sort":
                            sa2.QuickSort(array2, 0, array2.Count - 1);
                            break;
                        case "Quick Sort with Bubble Sort":
                            sa2.QuickSortWithBubbleSort(array2, 0, array2.Count - 1);
                            break;
                        case "Selection Sort":
                            sa2.SelectionSort(array2);
                            break;
                        case "Shell Sort":
                            sa2.ShellSort(array2);
                            break;
                        case "Pigeon Hole Sort":
                            sa2.PigeonHoleSort(array2);
                            break;
                    }
                    if (chkAnimation.Checked)
                        sa2.CreateAnimation();
                    MessageBox.Show("Finish");
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message);
                }
            };

            if (alg1 != "")
            {
                Thread t = new Thread(ts);
                t.Start();
            }
            if (alg2 != "")
            {
                Thread t2 = new Thread(ts2);
                t2.Start();
            }
        }
Exemple #34
0
 private void quickSortMenuClicked(object sender, EventArgs e)
 {
     clearOldStuff();
     NumberSwapListener old = theAlgorithm.getNumberSwapListener();
     theAlgorithm = new QuickSort();
     theAlgorithm.setNumberSwapListener(old);
     initializeGUI();
 }