Programacion: Arreglos – Método burbuja

  Método burbuja – Arreglos

Hacer un programa con arreglos, y ordenar los elementos del arreglo mediante el Método burbuja.

#include<iostream.h>
#include<conio.h>
#define MAX 50
void leerarray(int,float []);
void burbuja (int,float []);
void muestra (int,float []);
void main()
{
float x[MAX];

int n;
cout<<"Ingrese limite del arreglo";
cin>>n;
leerarray(n,x);
burbuja (n,x);
cout<<endl<<"El arreglo ordenado es:"<<endl;
muestra(n,x);
getch();
}
void leerarray(int n,float a[])
{ for(int i=0;i<n;i++)
{
cout<<"Ingrese elemento "<<i<<":";
cin>>a[i];
}
}
void burbuja (int n,float a[])
{
int i,j;
float temp;
for(i=1;i<n;i++)
for(j=n-1;j>=i;j--)
if(a[j-1]>a[j])
{
temp=a[j-1];
a[j-1]=a[j];
a[j]=temp;
}
}
void muestra (int n,float a[])
{
for(int i=0;i<n;i++)
cout<<" "<<a[i];
}

Te comparte el siguiente ejercicio donde se aplica el Método Burbuja en arreglos, pero con Struct: Struct con Arreglo – Método burbuja

-->