#include <iostream>
#include <string>
using namespace std;
void bubbleSort(int data[], int n);
int main()
{
cout << "Enter ten unsorted integers..." << endl;
int a[10];
for (int i = 0; i < 10; ++ i)
{
cout << "[" << i << "] = ";
cin >> a[i];
}
cout << endl << "Unsorted List = ";
for (int i = 0; i < 10; ++i)
cout << a[i] << ", ";
cout << endl;
cout << "Sorting..." << endl;
cout << "Sorted List = ";
bubbleSort(a, 10);
}
void bubbleSort(int data[], int n)
{
int j = 0;
bool nextEnd = true;
while (nextEnd)
{
nextEnd = false;
++j;
for (int i = 0; i < n - j; ++i)
{
if (data[i] > data[i+1])
{
int temp = data[i];
data[i] = data[i+1];
data[i+1] = data[i];
nextEnd = true;
}
}
}
for (int i = 0; i < 10; ++i)
cout << data[i] << ", ";
}
프로그램은 정말 간단합니다. 어레이에 10 개의 값을 입력하십시오. 그들을 분류되지 않은 것으로 표시하십시오. bubbleSort 함수로 보내고 정렬하고 마지막으로 정렬 된 목록을 표시합니다. 내가 가지고있는 문제는 출력 작업을 다시하지 못한다는 것입니다. 마지막 줄의 코드로 테스트했지만 작동하지 않습니다. 나는 정렬이 엉망이라고 생각하지 않는다. 정렬 된 목록을 올바르게 표시하려면 어떻게해야합니까?버블 정렬 디스플레이
출력을 표시하는 방식이 좋습니다. 문제는 버블 정렬에 있어야합니다 – prelic