document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.   Ejercicio: Algoritmo de Ordenacion Burbuja Mejorado
  3.   Autor:   Joel Fernandez
  4.   Fecha: 13/06/2014 8:45 p.m.
  5.   IDE: CodeBlocks
  6.   Pagina Web: http://codebotic.blogspot.com
  7.   Descripcion: Implementacion de algoritmo Bubble Sort Mejorado en C++
  8.  */
  9.  
  10. #include<iostream>
  11. #include<conio.h>
  12. #include<cstdlib>
  13. #define MAX 50
  14.  
  15. using namespace std;
  16. void LeerArreglo(int,float []);
  17. void BurbujaMejorado(int,float []);
  18. void MuestraArreglo(int,float []);
  19.  
  20. int main(void)
  21. {
  22.    system("color 0a");
  23.    float Numeros[MAX];
  24.    int n;
  25.    cout<<"\\t****************************************************\\n";
  26.    cout<<"\\t***  ALGORITMO DE ORDENAMIENTO BURBUJA MEJORADO  ***\\n";
  27.    cout<<"\\t***  ------------------------------------------  ***\\n";
  28.    cout<<"\\t****************************************************\\n\\n\\n";
  29.  
  30.    cout<<"\\n\\nNUMERO DE DATOS A LEER:"; cin>>n;
  31.  
  32.    LeerArreglo(n,Numeros);  //ingreso de datos en array
  33.    BurbujaMejorado(n,Numeros); // ordena por burbuja Mejorado
  34.    cout<<endl<<"\\n\\n LOS ELEMENTOS FUERON ORDENADOS \\n\\n"<<endl;
  35.    MuestraArreglo(n,Numeros); //muestra array ordenado
  36.  
  37.  
  38.     getch();
  39.     return 0;
  40. }
  41.  
  42. void BurbujaMejorado(int n, float x[])
  43. {
  44.     int i,j, bandera;
  45.     float aux;
  46.     for(i=1; i<n; i++)
  47.     {bandera=0;         //inciamos la bandera en 0
  48.      for(j=n-1; j>=i; j--)
  49.          {if(x[j-1]>x[j])
  50.          {aux = x[j-1];
  51.           x[j-1]=x[j];
  52.           x[j]=aux;
  53.           bandera=1; //si hubo cambio cambiamos la bandera a 1
  54.          }
  55.          }
  56.          if (bandera==0)
  57.         break; //si no hubo cambios entonces salir del for
  58.          }
  59.      }
  60.  
  61. void LeerArreglo(int n,float array[])
  62. { for(int i=0; i<n; i++)
  63.   {cout<<"\\n INGRESE ELEMENTO  ["<<i<<"]:  ";  cin>>array[i];}
  64.   }
  65.  
  66. void MuestraArreglo(int n, float array[])
  67. {int i;
  68.  for(i=0; i<n; i++)
  69.      cout<<"["<<array[i]<<"]  ";
  70. }
');