Guest User

Untitled

a guest
Jan 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arreglo[5]={71,32,83,47,53};
  6.  
  7. //seleccion
  8. //int aux,pos;
  9.  
  10. /*for(int i=0;i<5;++i)
  11. {
  12. aux=arreglo[i];
  13. pos=i;
  14. for(int j=i+1;j<5;++j)
  15. {
  16. if(arreglo[j]<aux)
  17. {
  18. pos=j;
  19. aux=arreglo[j];
  20.  
  21. }
  22.  
  23. }
  24. arreglo[pos]=arreglo[i];
  25. arreglo[i]=aux;
  26.  
  27. }*/
  28.  
  29. //insercion
  30. //int aux,pos;
  31. /*for(int i=1;i<5;++i)
  32. {
  33. pos=i;
  34. aux=arreglo[i];
  35. while(arreglo[pos-1]>arreglo[pos]&&pos>=0)
  36. {
  37. arreglo[pos]=arreglo[pos-1];
  38. pos--;
  39. arreglo[pos]=aux;
  40. }
  41.  
  42.  
  43. }*/
  44.  
  45. //burbuja mejorada
  46. int j=0;
  47. int aux;
  48. bool ordenado=false;
  49.  
  50. while(ordenado!=true)
  51. {
  52. ++j;
  53. ordenado=true;
  54. for(int i=0;i<5-j;++i)
  55. {
  56. if(arreglo[i]>arreglo[i+1])
  57. {
  58. aux=arreglo[i];
  59. arreglo[i]=arreglo[i+1];
  60. arreglo[i+1]=aux;
  61. ordenado=false;
  62.  
  63. }
  64.  
  65. }
  66.  
  67.  
  68. }
  69.  
  70.  
  71.  
  72.  
  73. for(int j=0;j<5;++j) cout<<arreglo[j]<<"\t";
  74. return 0;
  75. }
Add Comment
Please, Sign In to add comment