My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program of dynamic sort

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int n,*p;
  cout<<"enter the size of array: ";
  cin>>n;
  cout<<"enter the elements of array: ";
  p=new int[n];
  for(int i=0;i<n;i++)
  cin>>*(p+i);
  cout<<"values of array before sorting is: ";
  for(i=0;i<n;i++)
  cout<<*(p+i)<<" ";
  cout<<"\nvalues after sorting is: ";
  for(i=0;i<n;i++)
  {    int m;
       for(int j=i+1;j<n;j++)
       {   if(*(p+i)>*(p+j))
       { m=*(p+i);
         *(p+i)=*(p+j);
         *(p+j)=m;
       }
    }
  }
  for(i=0;i<n;i++)
  cout<<*(p+i)<<" ";
  getch();
 }

0 comments: