#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
void swap(int *a ,int *b)
{
int x=*a;
*a=*b;
*b=x;
}
int main()
{
int *a,n,i,j;
cout<<"\n enter the input array size .....\t";
cin>>n;
a=new int[n];
for(i=0;i<n;i++)
a[i]=rand()%(n+1);
float start=time(NULL);
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
if(a[j]>a[j+1])
swap(&a[j],&a[j+1]);
}
float end=time(NULL);
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<"\n------------------------------------------\ntime taken is .. \t" <<end-start<<endl;
return 0;
}
No comments:
Post a Comment