Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int arreglo[5]={71,32,83,47,53};
- //seleccion
- //int aux,pos;
- /*for(int i=0;i<5;++i)
- {
- aux=arreglo[i];
- pos=i;
- for(int j=i+1;j<5;++j)
- {
- if(arreglo[j]<aux)
- {
- pos=j;
- aux=arreglo[j];
- }
- }
- arreglo[pos]=arreglo[i];
- arreglo[i]=aux;
- }*/
- //insercion
- //int aux,pos;
- /*for(int i=1;i<5;++i)
- {
- pos=i;
- aux=arreglo[i];
- while(arreglo[pos-1]>arreglo[pos]&&pos>=0)
- {
- arreglo[pos]=arreglo[pos-1];
- pos--;
- arreglo[pos]=aux;
- }
- }*/
- //burbuja mejorada
- int j=0;
- int aux;
- bool ordenado=false;
- while(ordenado!=true)
- {
- ++j;
- ordenado=true;
- for(int i=0;i<5-j;++i)
- {
- if(arreglo[i]>arreglo[i+1])
- {
- aux=arreglo[i];
- arreglo[i]=arreglo[i+1];
- arreglo[i+1]=aux;
- ordenado=false;
- }
- }
- }
- for(int j=0;j<5;++j) cout<<arreglo[j]<<"\t";
- return 0;
- }
Add Comment
Please, Sign In to add comment