iss problem mai ssare compiler ka output different ayega?
mera diffrent aa rha h
Space time complexity
See this code
#include<iostream>
using namespace std;
void bubblesort(int a[], int n){
for (int itr = 1;itr<=n-1;itr++)
{
for (int j = 0;j<=(n-itr-1);j++)
{
if (a[j]>a[j+1])
{
swap(a[j],a[j+1]);
}
}
}
}
int main(){
int n;
cin>>n;
int a[10000];
for (int i = 0; i <n;i++)
{
a[i]=i;
}
clock_t t;
t = clock();
bubblesort(a,n);
t = clock() - t;
cout << "Using buuble sort function, it took " << (float)t/CLOCKS_PER_SEC << " seconds" << endl;
for (int i = 0; i<n;i++)
{
cout<<a[i]<<",";
}
return 0;
}
as your code is taking very less time, it is showing it to zero. Changed the clock function and increased the constraints and now it is working fine.