Bubble Sort in C#

 Bubble Sort 

Bubble sort is a simple sorting algorithm. This sorting algorithm is a comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they are not in order.

using System;


public class Solution

{


    static void BubbleSort(int[ ] arr)

    {

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

  {

  for(int j=0; j < arr.Length-1; j++)

  {

  if(arr[ j ] > arr[ j+1 ])

{

  int temp = arr[ j ];

  arr [ j ] = arr[ j+1 ];

  arr [ j+1 ] = temp;

               

}

  }

  } 

foreach(var num in arr)

{

   Console.Write(num + " ");

}

}


   public static void Main(String[] args)

    {       

    int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), arrTemp => Convert.ToInt32(arrTemp));       

        BubbleSort(arr);    

    }

}