Hi,

Can anyone tell me what type of sorts is my code?

static void Main(string[] args)
        {
            int[] array = { 108, 112, 87, 71, 49, 105, 49, 78, 63, 42 };
            int length = array.Length;

            int a, b, t;

            Console.Write("Original array:");
            for (int i = 0; i < length; i++)
                Console.Write(" " + array[i]);
            Console.WriteLine();

            for(a = 1; a < length; a++)
                for (b = length - 1; b >= a; b--)
                {
                    if (array[b - 1] < array[b])
                    {
                        t = array[b - 1];
                        array[b - 1] = array[b];
                        array[b] = t;
                    }
                }
            Console.Write("Sorted array: ");
            for (int i = 0; i < length; i++)
                Console.Write(" " + array[i]);
            Console.WriteLine();
            Console.ReadKey();
        }

Recommended Answers

Bubble sort with no optimizing done

Jump to Post

All 2 Replies

Bubble sort with no optimizing done

And he can know it, because he's the expert ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.