Exemplo n.º 1
0
        public int SortAscWrite()
        {
            int count = UnsortedList.Count;

            float[] usTab = UnsortedList.ToArray();
            var     temporaryList = new List <float>();
            int     ca = 0, cb = 0;

            Console.WriteLine("Bubble sort started work on following set:");
            ObjSort.DisplayList(this.UnsortedList);

            for (int i = 0; i < count - 1; i++)
            {
                bool changed = false;
                for (int j = 0; j < count - i - 1; j++)
                {
                    if (usTab[j] > usTab[j + 1])
                    {
                        changed = true;
                        float temp = usTab[j];
                        usTab[j]     = usTab[j + 1];
                        usTab[j + 1] = temp;
                        // wyświetlanie
                        for (int k = 0; k < usTab.Length; k++)
                        {
                            if (k == j || k == j + 1)
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.Write("  |" + usTab[k]);
                                Console.ForegroundColor = ConsoleColor.White;
                            }
                            else
                            {
                                Console.Write("  |" + usTab[k]);
                            }
                        }
                        Console.WriteLine();
                        ca++;
                    }
                    else
                    {
                        cb++;
                    }
                }
                if (!changed)
                {
                    break;
                }
            }
            for (int i = 0; i < count; i++)
            {
                temporaryList.Add(usTab[i]);
            }
            SortedList = temporaryList;
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine($"Sortowanie zakończone, liczba kroków: {ca} + {cb} jeśli liczyć te bez zamiany elementów");
            return(ca + cb);
        }
Exemplo n.º 2
0
        public int SortAscWrite()
        {
            var count = UnsortedList.Count;

            float[] usTab = UnsortedList.ToArray();
            int     ca    = 0;

            Console.WriteLine("Select sort started work on following set:");
            ObjSort.DisplayList(this.UnsortedList);

            for (int i = 0; i < count; i++)
            {
                int lowestIndex = i;
                for (int j = i + 1; j < count; j++)
                {
                    if (usTab[j] < usTab[lowestIndex])
                    {
                        lowestIndex = j;
                    }
                    ca++;
                }
                float temp = usTab[i];
                usTab[i]           = usTab[lowestIndex];
                usTab[lowestIndex] = temp;
                // wyświetlanie
                for (int k = 0; k < usTab.Length; k++)
                {
                    if (k == i || k == lowestIndex)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write("  |" + usTab[k]);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else
                    {
                        Console.Write("  |" + usTab[k]);
                    }
                }
                Console.WriteLine();
            }

            var temporaryList = new List <float>();

            for (int i = 0; i < count; i++)
            {
                temporaryList.Add(usTab[i]);
            }
            SortedList = temporaryList;
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine($"Sortowanie zakończone, liczba kroków: {ca}");
            return(ca);
        }
Exemplo n.º 3
0
        public int SortAscWrite()
        {
            int n = UnsortedList.Count;

            usTab = UnsortedList.ToArray();
            int ca = 0;

            Console.WriteLine("Heap sort started work on following set:");
            ObjSort.DisplayList(this.UnsortedList);

            for (int i = n / 2 - 1; i >= 0; i--)
            {
                ca += heapifyWrite(n, i);
            }
            for (int i = n - 1; i >= 0; i--)
            {
                float temp = usTab[0];
                usTab[0] = usTab[i];
                usTab[i] = temp;
                // wyświetlanie
                for (int k = 0; k < usTab.Length; k++)
                {
                    if (k == i || k == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write("  |" + usTab[k]);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else
                    {
                        Console.Write("  |" + usTab[k]);
                    }
                }
                Console.WriteLine();
                ca++;
                ca += heapifyWrite(i, 0);
            }
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine($"Sortowanie zakończone, liczba kroków: {ca}");
            LoadSorted(usTab);
            return(ca);
        }
Exemplo n.º 4
0
        public int SortAscWrite()
        {
            int count = UnsortedList.Count;

            float[] usTab         = UnsortedList.ToArray();
            var     temporaryList = new List <float>();

            ca = 0;

            Console.WriteLine("Bubble sort started work on following set:");
            ObjSort.DisplayList(this.UnsortedList);

            QuickWrite(usTab, 0, count - 1);

            for (int i = 0; i < count; i++)
            {
                temporaryList.Add(usTab[i]);
            }
            SortedList = temporaryList;

            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine($"Sortowanie zakończone, liczba kroków: {ca}");
            return(ca);
        }