This code work, but I firgue the style is very inefficient. As a good programmer, a decent style of writing is significant. Any good suggestions from experts? Does it have a huge memory leak?
int main ( )
{
int data [] = { 7, 3, 9, 2, 5};
int tmp;
for( int i = 0; i < 5; i++)
cout << data[i] << " ";
cout << endl;
for (int i = 0; i < 5 -1; i++)
for (int j = i+1; j < 5; j++)
if (data[i] > data[j])
{
tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
for( int i = 0; i < 5; i++)
cout << data[i] << " ";
cout << endl;
system ("pause");
return 0;
}
7 3 9 2 5
2 3 5 7 9
Press any key to continue . . .