Example #1
0
        static async Task <int> PartitionAsync(List <int> list, int low, int high, StackPanel stackPanel)
        {
            int pivot = list[high];
            int j     = low - 1;

            for (int i = low; i <= high - 1; i++)
            {
                //For stopping the algorithm in case user wants to stop.
                if (SharedClass.IsActive == false)
                {
                    break;
                }

                if (list[i] < pivot)
                {
                    j++;
                    SharedClass.SwapItems(i, j, stackPanel);
                }

                await Task.Delay(SharedClass.speed);
            }

            SharedClass.SwapItems(j + 1, high, stackPanel);
            return(j + 1);
        }
Example #2
0
        public static async Task SelectionSortAsync(StackPanel stackPanel)
        {
            for (int j = 0; j < InitializationClass.currentRandomList.Count - 1; j++)
            {
                int small = j;


                for (int i = j + 1; i < InitializationClass.currentRandomList.Count; i++)
                {
                    //For stopping the algorithm in case user wants to stop.
                    if (SharedClass.IsActive == false)
                    {
                        return;
                    }

                    if (InitializationClass.currentRandomList[i] < InitializationClass.currentRandomList[small])
                    {
                        small = i;
                    }
                    else
                    {
                    }
                }

                SharedClass.SwapItems(j, small, stackPanel);

                await Task.Delay(SharedClass.speed);
            }
        }
Example #3
0
        public static async Task BubbleSortAsync(StackPanel stackPanel)
        {
            for (int i = 0; i < InitializationClass.currentRandomList.Count - 1; i++)
            {
                for (int j = 0; j < InitializationClass.currentRandomList.Count - 1 - i; j++)
                {
                    if (SharedClass.IsActive == false)
                    {
                        return;
                    }

                    if (InitializationClass.currentRandomList[j] > InitializationClass.currentRandomList[j + 1])
                    {
                        SharedClass.SwapItems(j, j + 1, stackPanel);
                    }
                    await Task.Delay(SharedClass.speed);
                }
            }
        }