4

Shell Sort Diagrama

Embed Size (px)

Citation preview

Page 1: Shell Sort Diagrama
Page 2: Shell Sort Diagrama

#include<iostream>

using namespace std;

int main()

{

int Cantidad,Vector[50],i,j,k,b,Aux,l;

cout<<"METODO DE SHELL: "<<endl;

cout<<"tingrese la cantida de elementos: ";

cin>>Cantidad;

for(i=1;i<=Cantidad;i++)

{

cout<<" "<<i<<".. =";

cin>>Vector[i];

}

b = Cantidad / 2;

while(b>0)

{

Page 3: Shell Sort Diagrama

for(i=b+1;i<=Cantidad;i++)

{

j = i - b;

while(j>0)

{

k = j + b;

if(Vector[j]<Vector[k])

j=0;

else

{

Aux = Vector[j];

Vector[j] = Vector[k];

Vector[k] = Aux;

}

j = j - b;

}

}

b = b / 2;

}

cout<<endl;

cout<<" VECTOR ORDENADO "<<endl;

for(i=1;i<=Cantidad;i++)

cout<<" "<<Vector[i];

return 0;

}