EJERCICIO EN C 002-metodo de ordenacion por "seleccion"---!!comenten!!
NOTA: BUENO ACA LES DEJO UN PROBLEMA SOBRE CUANTAS PASADAS "UTILES REALIZA EL ALGORITMO DE BUSQUEDAD ,PUES SOLO CONTAMOS CADA VEZ QUE SE REALIZA UN CAMBIO DE LOS NUMEROS:COMENTEN,,,=)!!
// metodo de ordenacion por "seleccion" aplicado a 10 numeros
# include <iostream.h>
# include <conio.h>
# define LIM 30
main()
{ clrscr();
int i,j,x[LIM],pos,t,temp,con,band;
cout<<"\n Ingrese la siguiente serie de numeros: 9-7-10-3-8-2-1-5-6-4 ";
con=0;
for(i=0;i<10;i++)
{ cout<<"\n"<<(i+1)<<" elemento: ";cin>>x[i];cout<<endl;
};
for(i=0;i<9;i++)
{ band=0;
pos=i;
temp=x[i];
for(j=i+1;j<10;j++)
{
if(x[j]<temp)
{ pos=j;
band=1;
temp=x[j];}
};
x[pos]=x[i];
x[i]=temp;
if(band!=0)
{con=con+1;
cout<<(i+1)<<" pasada: ";
for(t=0;t<10;t++)
{cout<<" "<<x[t];}
cout<<endl;
}
};
cout<<endl<<"\n EL TOTAL DE PASOS ES: "<<con;
cout<<"\n\n LA SERIE ORDENADA ES: \n"<<endl;
for(t=0;t<10;t++)
{ cout<<"->"<<x[t];
};
getche();
}
Posted on 0:40 by ▓▒ø╗¢╣MigueL AnGel╗¢╝▒▓ and filed under
EJERCICIOS EN LENGUAJE C DE PROBLEMAS
| 0 Comments »
// metodo de ordenacion por "seleccion" aplicado a 10 numeros
# include <iostream.h>
# include <conio.h>
# define LIM 30
main()
{ clrscr();
int i,j,x[LIM],pos,t,temp,con,band;
cout<<"\n Ingrese la siguiente serie de numeros: 9-7-10-3-8-2-1-5-6-4 ";
con=0;
for(i=0;i<10;i++)
{ cout<<"\n"<<(i+1)<<" elemento: ";cin>>x[i];cout<<endl;
};
for(i=0;i<9;i++)
{ band=0;
pos=i;
temp=x[i];
for(j=i+1;j<10;j++)
{
if(x[j]<temp)
{ pos=j;
band=1;
temp=x[j];}
};
x[pos]=x[i];
x[i]=temp;
if(band!=0)
{con=con+1;
cout<<(i+1)<<" pasada: ";
for(t=0;t<10;t++)
{cout<<" "<<x[t];}
cout<<endl;
}
};
cout<<endl<<"\n EL TOTAL DE PASOS ES: "<<con;
cout<<"\n\n LA SERIE ORDENADA ES: \n"<<endl;
for(t=0;t<10;t++)
{ cout<<"->"<<x[t];
};
getche();
}