C++ rest of my codes aren't loading
Here's what I have so far. When I compile, I get no errors.
// 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");
}
The problem is when I run the codes, the only line I get is "The unsorted
values are 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Press any
key to continue..."
Why won't the rest of codes run after I press any key?
Thanks for the help.
No comments:
Post a Comment