+ 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

18th Dec 2017, 2:30 PM
Muhammad Savad
Muhammad Savad - avatar
3 odpowiedzi
+ 6
It's in lesson factory :(
18th Dec 2017, 3:20 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 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. } }
18th Dec 2017, 2:35 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
0
@Pegasus Sorry, I should have posted the link. Silly me. https://www.sololearn.com/learn/650/?ref=app
18th Dec 2017, 4:21 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar