Hi every one,
I am trying to implement the Prim’s algorithm. There is no error, but when I run the program an error window appears:
"general protection exception pa.cpp
pa(2) 0x22ef:0x01ab processor fault".
And I have to run this program 3 times with different size of array: "the size is 100,1000,and 1000000".
What should I do? Is there a site that is running these sizes of programs?
This is the code:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
int cost[10][10],k,i,j,stk[10],top,v,visit[10],visited[10],u;
int o[]={30,43,56,18,33,14,40,49,53,11,58,38,54,8,6,15,13,33,39,41,20,28,50,3,59,3,8,46,36,13,
12,17,18,54,37,22,14,1,22,60,59,32,12,20,45,42,36,47,13,30,46,26,47,41,6,45,60,17,43,
18,30,9,25,45,43,1,44,21,15,8,32,18,27,25,47,35,59,22,30,8,43,12,41,12,50,39,30,48,20,
35,41,55,38,45,49,11,4,19,19,11,22};
int p[]={11,4,19,19,11,30,43,56,18,33,14,40,49,53,11,58,38,54,8,6,15,13,33,39,41,20,28,50,3,59
,3,8,46,36,13,12,17,18,54,37,22,14,1,22,60,59,32,12,20,45,42,36,47,13,30,46,26,47,41,
6,45,60,17,43,18,30,9,25,45,43,1,44,21,15,8,32,18,27,25,47,35,59,22,30,8,43,12,41,12,
50,39,30,48,20,35,41,55,38,45,49,33};
main()
{
int m=100,c,n=75;
for(k=1;k<=m;k++)
{
i=o[k];
j=p[k];
c=rand()%20;
cost[i][j]=c;
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]==0)
cost[i][j]=31999;
cout <<"ORDER OF VISITED VERTICES";
k=1;
while(k<n)
{
m=31999;
if(k==1)
{
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(cost[i][j]<m)
{
m=cost[i][j];
u=i;
}
}
else
{
for(j=n;j>=1;j--)
if(cost[v][j]<m && visited[j]!=1 && visit[j]!=1)
{
visit[j]=1;
stk[top]=j;
top++;
m=cost[v][j];
u=j;
}
}
cost[v][u]=31999;
v=u;
cout<<v << " ";
k++;
visit[v]=0; visited[v]=1;
}
}