0

I have written this code to variably test Prim's algorithm and I am timing it using clock(). For some reason it always returns 0 as its running time. I have other code that I have used this exact implementation in and they are returning the currect running times. The code is very short and if anyone has any idea of why this is happening please let me know. I only have 4 more hours left on this project. Thanks in advance!

```
#include <iostream>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
int a,b,u,v,n,i,j,ne;
ne = 1;
int visited[1000] = {0},min,mincost=0,cost[1000][1000];
cout << "Enter the number of nodes:" << endl;
cin >> n;
for(int i=1; i<n; i++)
for(int j=1; j<=n; j++)
{
cost[i][j] = (rand()%1000)+1;
}
visited[1]=1;
cout << endl;
clock_t t;
float running_time;
while(ne<n)
{
for(i=1,min=1000;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]<min)
if(visited[i]!=0)
{
min=cost[i][j];
a=u=i;
b=v=j;
}
if(visited[u]==0 || visited[v]==0)
{
cout << "Edge: " << ne++ << endl;
cout << a << " " << b << endl;
cout << "Cost: " << min << endl;
mincost+=min;
visited[b]=1;
}
cost[a][b]=cost[b][a]=1000;
}
cout << "Min cost: " << mincost << endl;
t = clock();
t = clock() - t;
running_time = ((float)t/CLOCKS_PER_SEC);
cout << "The running time of this algorithm is: " << running_time << " seconds" << endl;
return 0;
}
```