Sunday, September 7, 2014

Shell Sort

//Program Using Shell Sort

include
using namespace std;
main()
{
int arr[5]={4,2,7,1,9};
int i,j,k,num=5,t;
for(i=num/2;i>0;i=i/2)
{
for(j=i;j=0;k=k-i)
{
if(arr[k+i]>=arr[k])
break;
else
{
t=arr[k];
arr[k]=arr[k+1];
arr[k+1]=t;
}
}
}
}
for(int d=0;d<num;d++)
cout << arr[d] << endl;
}

5 comments:

  1. include
    using namespace std;
    main()
    {
    int arr[5]={4,2,7,1,9};
    int i,j,k,num=5,t;
    for(i=num/2;i>0;i=i/2)
    {
    for(j=i;j=0;k=k-i)
    {
    if(arr[k+i]>=arr[k])
    break;
    else
    {
    t=arr[k];
    arr[k]=arr[k+1];
    arr[k+1]=t;
    }
    }
    }
    }
    for(int d=0;d<num;d++)
    cout << arr[d] << endl;
    }

    ReplyDelete
  2. //Md. Monwar Hossain
    //Id. 201330705, Batch-44,
    #include
    using namespace std;
    main()
    {
    int data[5]={9,6,3,7,2},mennath,len;
    cin>>len;
    for(int i=len/2;i>0;i=i/2)
    {
    for(int j=i;j=0;k=k-i)
    {
    if(data[k+i]>=data[k])
    break;
    else
    {
    mennath=data[k];
    data[k]=data[k+1];
    data[k+1]=mennath;
    }
    }
    }
    }
    for(int m=0;m<len;m++)
    cout<<"\n"<<data[m];
    }

    ReplyDelete
  3. #include
    using namespace std;
    int main()
    {
    int a[5]={9,6,3,7,2};
    int num=5,temp;
    for(int i=num/2;i>0;i=i/2)
    {
    for(int j=i;j=0;k=k-i)
    {
    if(a[k+i]>a[k])
    break;
    else
    {

    temp=a[k];
    a[k]=a[k+1];
    a[k+1]=temp;
    }
    }
    }
    }
    for(int d=0;d<num;d++)
    cout<<"\n"<<a[d];
    }

    ReplyDelete
  4. #include
    using namespace std;
    main()
    {
    int a[5]={1,3,2,6,7};
    int num = 5, temp;
    for(int i=num/2 ;i>0; i=i/2 )
    {
    for(int j=i;j0; k=k-i)
    {

    if (a[k+i]>=a[k])
    break;
    else

    {
    temp=a[k];
    a[k]=a[k+i];
    a[k+i]=temp;
    }
    }
    }
    }
    for(int d=0; d<num; d++)
    cout <<a[d]<<endl;
    }

    ReplyDelete
  5. #include
    using namespace std;
    main()
    {
    int a[5]={1,3,2,6,7};
    int num = 5, temp;
    for(int i=num/2 ;i>0; i=i/2 )
    {
    for(int j=i;j0; k=k-i)
    {

    if (a[k+i]>=a[k])
    break;
    else

    {
    temp=a[k];
    a[k]=a[k+i];
    a[k+i]=temp;
    }
    }
    }
    }
    for(int d=0; d<num; d++)
    cout <<a[d]<<endl;
    }

    ReplyDelete