Bubble sort algorithm

hi please i need help to solve this problem!
Measure elapsed time for Bubble sort algorithm, for multiple array sizes N. so far this is only i have can u fix my cod pleas

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<time.h>
using namespace std;

void main()
{
	int max=5;
	int num[max]={2,1,3,4,0};
	int i,j;

	clock_t start = clock() / (CLOCKS_PER_SEC / 1000);      
   
for (i=0; i<max; i++)
	{
	for(j=i+1; j<max; j++)
		{
			if (num[i]>num[j])
				swap(num[i], num[j]);					
		}
	}
for (i=0; i<max; i++)
	cout<<num[i]<<",";

cout<<"\n\n";
 clock_t elapsed = clock() / (CLOCKS_PER_SEC / 1000) - start;


system("pause");
}

  Put the code you need help with here.
For something like this it will probably finish in a matter of microseconds. I would do something like this though
1
2
3
4
5
6
7
unsigned start = time(0);

//do stuff

unsigned end = time(0);

std::cout << end - start << std::endl; //number of seconds passed 


Also, main must return int and max must be a constant integer int const max = 5;

Though it looks like you are dividing it by 1000 so you are doing microseconds and not seconds.
Last edited on
Topic archived. No new replies allowed.