Untitled
By: a guest | Mar 20th, 2010 | Syntax:
None | Size: 0.92 KB | Hits: 76 | Expires: Never
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <iomanip>
#include <fstream>
using namespace std;
void bubblesort(int a[], int n)
{
int i,j;
int tmp;
int change;
for(i=0;i<n-1;i++)
{
change=0;
for(j=0;j<n-1-i;j++)
if(a[j+1]<a[j])
{
tmp=a[j];
a[j]=a[j+1];
a[j+1]=tmp;
change =1;
}
if(!change)break;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
ofstream pomiar;
pomiar.open ("pomiar babelkowe.txt");
clock_t tstart,tend;
int *tab;
int n=10000;
for(int l=0;l<10;l++)
{
pomiar<<n<<endl;
for(int k=0;k<20;k++)
{
tab=new int[n];
for(int i=0;i<n;i++)
{
tab[i]=rand()%100000;
}
tstart=clock();
bubblesort(tab,n);
tend=clock();
double t=(double)(tend-tstart)/CLOCKS_PER_SEC;
pomiar<<fixed<<setprecision(4)<<t;
pomiar<<endl;
}
n=n+10000;
}
pomiar.close();
delete []tab;
system("pause");
return 0;
}