+ 2
Write algorithm of bubble sort or exchange sort?
it is oldest and simplest algorithm. Algorithm step 1:compare adjacent elements . if the first is greater than second swap them step 2:do this for each pair of adjacent element starting with the first two and ending with last two at this point the last elements should be greatest step 3: repeat the step for all element except last one
3 Respostas
+ 6
It's in lesson factory :(
+ 4
Here is the loop, for an n-sized array, arr.
Implement the swap() yourself or use std::swap().
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(arr[j]>arr[j+1]) swap(arr[j],arr[j+1]);
//Compares for ascending order.
}
}
0
@Pegasus
Sorry, I should have posted the link. Silly me.
https://www.sololearn.com/learn/650/?ref=app