Site Loader
Auckland, New Zealand
Bubble sorting an array using C# Algorithm Here is the code snippet
      private static int[] SortInt(int[] value)
        {
            int temp = 0;
            //Outer loop, to loop complete array
            for (int i = 0; i < value.Length; i++)
            {
                //Compare with its peer
                for (int j = 0; j < value.Length - 1; j++)
                {
                    //Check if the first is greater than second, if its then swap
                    if (value[j] > value[j + 1])
                    {
                        temp = value[j + 1];
                        value[j + 1] = value[j];
                        value[j] = temp;
                    }
                }
            }

            return value;
        }

Thanks, Karthik KK

Post Author: Karthik kk

Leave a Reply

Your email address will not be published. Required fields are marked *