python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
selection sort algorithm c#.net

selection sort algorithm c#.net

Hello everyone, I am going to share the code sample for the selection sort algorithms using c# with console application as given below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    public class SelectionSorting
    {
        public static void SelectionSort()
        {

            int[] arrayNumber = new int[100];
            int minNumber;
            bool isNumber = false;
            int sizeNumber;

            Console.WriteLine("Enter the mumbers of element in the array.");

            string sizeStr = Console.ReadLine();
            isNumber = Int32.TryParse(sizeStr, out sizeNumber);

            if (isNumber)
            {
                Console.WriteLine("Enter array values numeric.");
                for (int i = 0; i < sizeNumber; i++)
                {
                    int tempVal;
                    string arrayValue = Console.ReadLine();
                    isNumber = Int32.TryParse(arrayValue, out tempVal);
                    if (isNumber)
                    {
                        arrayNumber[i] = tempVal;
                    }
                    else
                    {
                        Console.WriteLine("Enter the array numeric only values.");
                        break;
                    }
                }

                for (int j = 0; j < sizeNumber - 1; j++)
                {
                    minNumber = j;

                    for (int k = j + 1; k < sizeNumber; k++)
                    {
                        if (arrayNumber[minNumber] > arrayNumber[k])
                        {
                            minNumber = k;
                        }
                    }

                    if (minNumber != j)
                    {
                        int finalNum = arrayNumber[j];
                        arrayNumber[j] = arrayNumber[minNumber];
                        arrayNumber[minNumber] = finalNum;
                    }
                }

                Console.WriteLine("Results of Selection Sort.");
                for (int l = 0; l < sizeNumber; l++)
                {
                    Console.WriteLine(arrayNumber[l]);
                }
            }
            else
            {
                Console.WriteLine("The array numeric only.");
            }
        }

        static void Main()
        {
            SelectionSort();
            Console.Read();
        }
    }

}
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions