Bubble Sort Function

Our function will receive an array as the input.

The steps of bubble sort explained below:

  • Create the temp variable to store the value of certain index.
var temp = 0
  • Loops throughout the array.
  • It takes two loops operation, to repatedly swapping the element.
for (int i = 0; i < input.Length; i++)
{
    for (int j = i + 1; j < input.Length; j++ )
    {

    }
}
  • Swap the element if meets certain conditional statement.
if (input[i] > input[j])
{
    Console.WriteLine(input[i] + " " + input[j]);
    temp = input[i];
    input[i] = input[j];
    input[j] = temp;
}

results matching ""

    No results matching ""