Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Ejercicio: Algoritmo de Ordenacion Burbuja Mejorado
- Autor: Joel Fernandez
- Fecha: 13/06/2014 8:45 p.m.
- IDE: CodeBlocks
- Pagina Web: http://codebotic.blogspot.com
- Descripcion: Implementacion de algoritmo Bubble Sort Mejorado en C++
- */
- #include<iostream>
- #include<conio.h>
- #include<cstdlib>
- #define MAX 50
- using namespace std;
- void LeerArreglo(int,float []);
- void BurbujaMejorado(int,float []);
- void MuestraArreglo(int,float []);
- int main(void)
- {
- system("color 0a");
- float Numeros[MAX];
- int n;
- cout<<"\t****************************************************\n";
- cout<<"\t*** ALGORITMO DE ORDENAMIENTO BURBUJA MEJORADO ***\n";
- cout<<"\t*** ------------------------------------------ ***\n";
- cout<<"\t****************************************************\n\n\n";
- cout<<"\n\nNUMERO DE DATOS A LEER:"; cin>>n;
- LeerArreglo(n,Numeros); //ingreso de datos en array
- BurbujaMejorado(n,Numeros); // ordena por burbuja Mejorado
- cout<<endl<<"\n\n LOS ELEMENTOS FUERON ORDENADOS \n\n"<<endl;
- MuestraArreglo(n,Numeros); //muestra array ordenado
- getch();
- return 0;
- }
- void BurbujaMejorado(int n, float x[])
- {
- int i,j, bandera;
- float aux;
- for(i=1; i<n; i++)
- {bandera=0; //inciamos la bandera en 0
- for(j=n-1; j>=i; j--)
- {if(x[j-1]>x[j])
- {aux = x[j-1];
- x[j-1]=x[j];
- x[j]=aux;
- bandera=1; //si hubo cambio cambiamos la bandera a 1
- }
- }
- if (bandera==0)
- break; //si no hubo cambios entonces salir del for
- }
- }
- void LeerArreglo(int n,float array[])
- { for(int i=0; i<n; i++)
- {cout<<"\n INGRESE ELEMENTO ["<<i<<"]: "; cin>>array[i];}
- }
- void MuestraArreglo(int n, float array[])
- {int i;
- for(i=0; i<n; i++)
- cout<<"["<<array[i]<<"] ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement