这是我到目前为止所拥有的。当我编译时,我没有收到任何错误。
// Sorting Benchmarks
#include <iostream>
using namespace std;
// Function Prototypes
int bubbleSort (long [], int);
void showArray (long [], int);
int main()
{
// Define an array with unsorted values
const int SIZE = 20;
long values[SIZE] = {20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
int n;
// Display the values.
cout << "The unsorted values are\n";
showArray(values, SIZE);
// Sort the values using bubble sort
n = bubbleSort (values, SIZE);
// Display the number of exchanges while using bubble sort
cout << n;
// Display the sorted values.
cout << "The sorted values are\n";
showArray (values, SIZE);
return 0;
}
int bubbleSort (long array[], int size)
{
bool swap;
int temp;
int exchanges;
exchanges = 0;
do
{
swap = false;
for(int count = 0; count < (size - 1); count++)
{
if (array[count] > array[count + 1]);
{
array[count + 1] = temp;
swap = true;
exchanges++;
}
}
}
while (swap);
return exchanges;
}
void showArray(long array[], int size)
{
for(int count = 0; count < size; count++)
cout << array[count] << " ";
cout << endl;
system("PAUSE");
}
问题是当我运行代码时,我得到的唯一一行是“未排序的值是 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 按任意键继续...”
为什么我按任意键后其余代码都不会运行?
谢谢您的帮助。