snippetcMinor
Bubble sort code
Viewed 0 times
codesortbubble
Problem
I tried avoiding nested loops and usage of too many variables. This is up for review and comments.
void bubble_Sort(int *arr, int n)
{
int i = 0;
int* temp = arr;
while(n > 1)
{
if(i == (n-1))
{
i=0;
n--;
temp = arr;
}
if(*temp > *(temp+1))
{
*temp ^= *(temp+1);
*(temp+1) ^= *temp;
*temp ^= *(temp+1);
}
temp++;
i++;
}
}Solution
This code is totally cryptic to me. Had you not named the function
You should document the purpose of the variables used, or at least give them less generic names than
bubble_Sort or used it in the title of the question, I would have no clue what the code was supposed to do. Let alone trying to understand if it is implemented correctly.You should document the purpose of the variables used, or at least give them less generic names than
n, i, temp.Context
StackExchange Code Review Q#147611, answer score: 2
Revisions (0)
No revisions yet.