سلام.من کد زیر نوشتم.ولی runtime error داره.داخل حلقه while من ماتریس hel رو به تابع MAX میفرستم.که hel در ابتدا به ماتریس path اشاره میکنه.و بعد باید مقادیرش در هر مرحله از اجرای حلقه عوض بشه.ولی برنامه تو خط 65 ارور میده.
int MAX(int **p,int r,int size)
{
int *count=new int[size];
for(int i=0;i<r;i++)
count[i]=0;
for(int i=0;i<r;i++)
{
for(int j=0;j<size;j++)
{
if(p[i][j]==1)
count[i]++;
}
}
int max=count[0];
int temp=0;
for(int i=1;i<r;i++)
{
if(count[i]>max)
{
max=count[i];
temp=i;
}
}
return temp;
}
int tedad1=0;
int index=0;
int **hel;
hel=path;
int shomar=0;
while (tedad1<size)
{
int *J=new int[size];
for(int i=0;i<size;i++)
J[i]=0;
index=MAX(hel,size-tedad1,size);
arr[shomar]=index+1;
for(int i=0,k=0;i<size;i++)
{
if(path[index][i]==0)
{
J[k]=i;
k++;
}
else
{
tedad1++;
}
}
for(int i=0;i<size-tedad1;i++)
{
delete []hel[i];
hel[i]=0;
}
delete []hel;
hel=0;
hel=new int*[size-tedad1];
for(int i=0;i<size-tedad1;i++)
hel[i]=new int[size];
for(int i=0;i<size-tedad1;i++)
{
for(int j=0;j<size;j++)
{
hel[i][j]=path[J[i]][j];
}
}
shomar++;
}
cout<<'{';
for(int i=0;i<tedad;i++)
cout<<"U"<<arr[i]<<",";
cout<<'}';
cout<<endl;