Sort Array In C# Without Using Inbuilt Function | Sort Integer Array In C# Without Using Inbuilt Function by Asc/Desc

 int[] InputArr = new int[8] { 5, 6, 2, 9, 12, 3, 8, 4 };

            int temp = 0;


            for (int i = 0; i <= InputArr.Length - 1; i++)

            {

                for (int j = i + 1; j < InputArr.Length; j++)

                {

                    //if (InputArr[i] < InputArr[j])//For Desc Sort

                    if (InputArr[i] > InputArr[j])//For Asc Sort

                    {

                        temp = InputArr[i];

                        InputArr[i] = InputArr[j];

                        InputArr[j] = temp;

                    }

                }

            }


            foreach (var item in InputArr)

            {

                Console.WriteLine(item);

            }

Comments

Popular posts from this blog

Uploading Image to Sql Server Image Datatype in asp.net using fileupload Control

Get Running Sum of Query SQL Query