Wednesday 26 October 2011

implementation of insertion sort

//program is implemented by shadab khan
#include<iostream.h>
#include<conio.h>
void main()
{
            clrscr();
            int a[5], i,t,p;
            cout<<”enter the 4 element of array”;
            for(i=1;i<=4;i++)
            cin>>a[0];
            a[0]=NULL;
            for(i=2;i<=4;i++)
            {
                        t=a[i];
                        p=i-1;
                        while(t<a[p])
                        {
                        a[p+1]=a[p];
                        P=p-1;
                        }
            a[p+1]=t;
            }
            cout<<”Elements after insertion sort : \n\n”;
            for(i=0;i<=4;i++)
            {
                        cout<<a[i]<<endl;
            }
            getch();
}

No comments:

Post a Comment