C# program to implement selection Sort to arrange elements in the descending order

C# program to implement selection Sort to arrange elements in the descending order Article has many meanings. We are going to know this topic clearly through this article. We hope you like this article.

C# program to implement selection Sort to arrange elements in the descending order

C# program to implement selection Sort to arrange elements in the descending order

//C# program to implement selection Sort to arrange elements 
//in the descending order

using System;

class Sort
{
    static void SelectionSort(ref int []intArr)
    {
        int temp=0;
        int max =0;

        int i = 0;
        int j = 0;

        for (i = 0; i < intArr.Length - 1; i++)
        {
            max = i;

            for (j = i + 1; j < intArr.Length; j++)
            {
                if (intArr[j] > intArr[max])
                {
                    max = j;
                }
            }
            temp = intArr[max];
            intArr[max] = intArr[i];
            intArr[i] = temp;
        }
    }
    static void Main(string[] args)
    {
        int[] intArry = new int[5] { 65,34,23,76,21 };

        Console.WriteLine("Array before sorting: ");
        for (int i = 0; i < intArry.Length; i++)
        {
            Console.Write(intArry[i]+" ");
        }
        Console.WriteLine();

        SelectionSort(ref intArry);
        
        Console.WriteLine("Array before sorting: ");
        for (int i = 0; i < intArry.Length; i++)
        {
            Console.Write(intArry[i] + " ");
        }
        Console.WriteLine();
    }
}
Array before sorting:
65 34 23 76 21
Array before sorting:
76 65 34 23 21
Press any key to continue . . .

Final Words

C# program to implement selection Sort to arrange elements in the descending order We got to know our topic very clearly. And if you have any doubts about this article you can let us know your doubts via comment.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment