top of page

//METODOS DE ORDENAMIENTO
#include<iostream>
#include<conio.h>
using namespace std;
int num[] = {8,5,3,1,10};
int NUM[] = {7,6,5,9,8};
int m,n,i,pos,aux,j,k,Min,Aux,auxi;
void Imprimir(int[], int n );
void shell(int [], int n);
int main()
{
    int opcion;
    do
    {
    cout<<"\n******************menu*************";
    cout<<"\n1) Ordenamiento por Insercion   ";
    cout<<"\n2) Ordenamiento por Seleccion ";
    cout<<"\n3) Metodo Shell  ";
    cout<<"\n4) Metodo de la burbuja  ";
    
    cin>>opcion;
    switch(opcion)
     {
             case 1:
      {
       for(i=0;i<10;i++)
       {
          pos=i;
          aux= num[i];    
          while((pos>0)&& (num[pos-1]>aux))
           {
              num[pos]=num[pos-1];
              pos--;
             }
          num[pos]=aux;
       }
         cout<<"ORDEN ASCENDENTE: "; 
         for(i=0;i<10;i++)
         {
             cout<<num[i]<<" ";
         }
          cout<<"\nORDEN DESCENDENTE: "; 
         for(i=8;i>=0;i--)
         {
             cout<<num[i]<<" ";
         }  
       } break;
       case 2:
           {
             for(j=0;j<10;j++)
             {
                 Min = j;
                for(k=j+1;k<10;k++)
                {
                    if(num[k]<num[Min])
                    {
                        Min=k;
                    }
                    
                }
                   Aux=num[j];
                   num[j]=num[Min];
                   num[Min]=Aux;
             }
              cout<<"ORDEN ASCENDENTE: "; 
             for(j=0;j<10;j++)
             {
                  cout<<num[j]<<" ";
             }
              cout<<"\nORDEN DESCENDENTE: "; 
             for(j=8;j>=0;j--)
             { 
                cout<<num[j]<<" ";
             } 
          
           } break;
        case 3:
            {
                int total;
                cout<<"Cuanros numeros tiene el arreglo"<<endl;
                cin>>total;
                int Num[total];
                for(int z=0 ;z<total;z++)
                {
                    cout<<"Ingresar numero para posicion ["<<(z+1)<<"] del arreglo"<<endl;
                    cin>>Num[z];
                }
                shell(Num,total);
                Imprimir(Num,total);
                
            }break;
        case 4:
            {
                for(m=0;m<9;m++)
                {
                    for(n=0;n<9;n++)
                    {
                        if(NUM[n]>NUM[n+1])
                        {
                        auxi=NUM[n];
                        NUM[n]=NUM[n+1];
                        NUM[n+1]=auxi;
                        }
                    }
                }
                cout<<"ORDEN ASCENDENTE:";
                for(m=0;m<9;m++)
                {
                    cout<<NUM[m]<<"";
                }
            }
           
     }

}while(opcion!=0);
}
//Zona de funciones
void shell(int a[], int n)
{
    int ints,z,AUX;
    bool band; 
    ints=n;
    while(ints>1)
    {
        ints=(ints/2);
        band=true;
        while(band==true)
        {
            band=false;
            z=0;
            while((z+ints)<=n)
            {
                if(a[z]> a[z+ ints])
                {
                    AUX=a[z];
                    a[z]=a[z+ints];
                    a[z+ints]=AUX;
                    band=true;
                }
                z++;
            } 
        }
        
    }
}
void Imprimir(int a[] , int n)
{
    cout<<"Numeros ordenados de menor a mayor"<<endl;
    for (int z=0;z <n;z++)
    cout<<"["<<a[z]<<" ]";
}

metodos.PNG
Captura1.PNG
bottom of page