public void SortColumn(BvgColumn <TItem> parColumn)
        {
            if (parColumn.IsSorted)
            {
                parColumn.IsAscendingOrDescending = !parColumn.IsAscendingOrDescending;
            }
            else
            {
                foreach (var item in Columns.Where(x => x.IsSorted))
                {
                    item.IsSorted = false;
                    item.InvokePropertyChanged();
                }

                parColumn.IsSorted = true;
                parColumn.IsAscendingOrDescending = true;
            }

            parColumn.InvokePropertyChanged();


            SortState = Tuple.Create(true, parColumn.prop.Name, parColumn.IsAscendingOrDescending);


            if (parColumn.IsAscendingOrDescending)
            {
                OnSort?.Invoke(parColumn.prop.Name);
            }
            else
            {
                OnSort?.Invoke(parColumn.prop.Name + " desc");
            }
        }
예제 #2
0
        public static void SortArrayInThread()
        {
            OnSort += SortEventHandler;


            new Thread(() =>
            {
                int length     = 15;
                Random rnd     = new Random();
                int[] IntArray = new int[length];
                for (int i = 0; i < IntArray.Length; i++)
                {
                    IntArray[i] = rnd.Next(0, 100);
                }
                Thread.Sleep(5000);
                SortHandler.SortArray(IntArray, (a, b) => a > b);
                OnSort?.Invoke("\nSorting is complete INT\n");
            }).Start();
            new Thread(() =>
            {
                int length           = 15;
                Random rnd           = new Random();
                double[] DoubleArray = new double[length];
                for (int i = 0; i < DoubleArray.Length; i++)
                {
                    DoubleArray[i] = rnd.NextDouble() * 100;
                }
                Thread.Sleep(5000);
                SortHandler.SortArray(DoubleArray, (a, b) => a > b);
                OnSort?.Invoke("\nSorting is complete DOUBLE\n");
            }).Start();
            new Thread(() =>
            {
                string[] StringArray = new string[]
                {
                    "afg", "uydd", "fjsfgfg", "adddd", "jddgfg", "bag", "lklolkl"
                };
                Thread.Sleep(5000);
                SortHandler.SortArray(StringArray, (a, b) => (!SortHandler.CompareString(a, b)));
                OnSort?.Invoke("\nSorting is complete STRING\n");
            }).Start();
            new Thread(() =>
            {
                while (_threadCount != 3)
                {
                    Thread.Sleep(500);
                    Console.WriteLine("Sorting...");
                }
                ;
            }).Start();
        }
예제 #3
0
        public void CustomSort <T>(T[] mas, Func <T, T, bool> ComparerDelegate)
        {
            T temp;

            for (int i = 0; i < mas.Length; i++)
            {
                for (int j = i + 1; j < mas.Length; j++)
                {
                    if (ComparerDelegate(mas[i], mas[j]))
                    {
                        temp   = mas[i];
                        mas[i] = mas[j];
                        mas[j] = temp;
                    }
                }
            }
            OnSort.Invoke();
            Show(mas);
        }
예제 #4
0
        private void btnSort_Click(object sender, EventArgs e)
        {
            var numToSortString = tbxInput.Text;

            if (!string.IsNullOrEmpty(numToSortString))
            {
                var numbers    = numToSortString.Split(' ', ',');
                var numsToSort = new List <int>();
                foreach (var numberString in numbers)
                {
                    int number;
                    if (int.TryParse(numberString, out number))
                    {
                        numsToSort.Add(number);
                    }
                }
                AddDisplay("To Sort:", numsToSort);

                OnSort?.Invoke(this, new SortEventArgs(numsToSort));
            }
        }
예제 #5
0
        public static void CustomSort <T>(T[] Array, Func <T, T, bool> ElementComparison)
        {
            if (ElementComparison == null)
            {
                return;
            }
            T tempValue;

            for (int i = 0; i < Array.Count() - 1; i++)
            {
                for (int j = i + 1; j <= Array.Count() - 1; j++)
                {
                    if (ElementComparison.Invoke(Array[j], Array[i])) //Array[j] < Array[i]
                    {
                        tempValue = Array[i];
                        Array[i]  = Array[j];
                        Array[j]  = tempValue;
                    }
                }
            }
            OnSort?.Invoke();
        }