Upload new file

parent 61c63d74
#include <algorithm>
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main(){
int n=100,a[n];
int count=0;
int i=50;
for(int i=0;i<n;i++){
a[i]=i+1;
}
//random_shuffle(a,a+n);
int found=1;
int start=clock();
while(found!=0){
found=0;
for(int j=0;j<n-1;j++){
if(a[j]>a[j+1]) {int temp=a[j];a[j]=a[j+1];a[j+1]=temp;found++;}
}
}
found=1;
int k=n;
//random_shuffle(a,a+n);
int stop=clock();
cout<<stop-start<<" ";
start=clock();
while(found!=0){
found=0;
for(int j=0;j<k-1;j++){
if(a[j]>a[j+1]) {int temp=a[j];a[j]=a[j+1];a[j+1]=temp;found++;}
}
k--;
}
stop=clock();
cout<<stop-start<<" ";
}
/*
time taken to sort 100 distinct numbers is 138
time taken to sort 100 distinct numbers using improvised bubblesort is 95
time taken to sort 100 sorted distinct numbers is 2
time taken to sort 100 distinct numbers using improvised bubblesort is 2
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment