Write a program to implement bubble sort on a hardcoded array and print each step of the sorting process.
MediumProblem Statement
Write a program to implement bubble sort on a hardcoded array and print each step of the sorting process.
Sample Input
Array: [5, 3, 8, 6, 2]
Sample Output
Step 1: 3, 5, 6, 2, 8 Step 2: 3, 5, 2, 6, 8 Step 3: 3, 2, 5, 6, 8 Step 4: 2, 3, 5, 6, 8
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
using System;
class BubbleSortSteps
{
static void Main()
{
// Implement bubble sort and print each step
}
}
Input
Array: [5, 3, 8, 6, 2]
Expected Output
Step 1: 3, 5, 6, 2, 8 Step 2: 3, 5, 2, 6, 8 Step 3: 3, 2, 5, 6, 8 Step 4: 2, 3, 5, 6, 8