Bubble sort

Vediamo un brese e semplice esempio realizzato in c++ di ordinamento BUBBLE SORT

Problema: Ordinare un array di 8 elementi (5 2 8 4 7 1 3 6) utilizzando l’algoritmo di ordinamento Bubble sort.

Codice.cpp

#include <iostream>
using namespace std;
 
void bubble(int A[],int n){
 int flag=1;
 int stop=n-1;
 while(flag==1){
 flag=0;
 for(int i=0; i < stop; i++){
 if(A[i]>A[i+1]){
 int t;
 t=A[i];
 A[i]=A[i+1];
 A[i+1]=t;
 flag=1;
 }
 }
 stop=stop-1;
 }
}
Tothebit

About Tothebit

Tothebit

How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site