c語言一維數組冒泡排序怎么輸出中間過程?
#include<iostream>
using namespace std;
void bubbleSort(int *arr,int len)
{
for (int i = 0; i < len - 1; i++)
{
for (int j = 0; j < len - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
for (int k = 0; k < len; k++)
{
if (k == 0)
{
cout << arr[k] ;
}
else
{
cout <<" "<< arr[k];
}
}
cout << endl;
}
}
int main()
{
int len = 0;
cin >> len;
int *arr = new int[len];
if (len == 1)
{
cin >> arr[0];
cout << arr[0];
}
else
{
for (int i = 0; i < len; i++)
{
cin >> arr[i];
}
bubbleSort(arr, len);
}
}