-1
我得到下面的代码段故障:C++分割故障for循环
Node *pointerArray[6];
int onesNeighbor[]={2,3,6};
Node *createNode(int localDistance)//////creates a node
{
Node *newNode;
newNode=new Node;
newNode->wasVisited=false;
newNode->shortestDistance=localDistance;
return newNode;
}
void insertNode(Node *n,int i)//////////////////connects nodes to the
{/////////////////////////////////////////array of pointers
pointerArray[i]=n;
}
for(i=1;i<7;i++)
{
if(i==1){
n=createNode(0);
cout<<i<<"\t"<<n->shortestDistance<<"\t";
for(int j=0;j<=2;j++)
cout<< onesNeighbor[j]<<",";
cout<<endl;
for (count = 1; count < 2; count++)
{
current = pointerArray[count];
if (count == 1)
{
for (int j = 0; j <= 2; j++)
{
lowest = current->shortestDistance;
current = pointerArray[onesNeighbor[j]];
if (current->shortestDistance < lowest)
{
lowest = current->shortestDistance;
closestNeighbor = onesNeighbor[j];
}
}
}
}
请帮助.....
线段故障发生在哪条线上? – TheFuzz 2011-05-03 00:53:23
我们需要看到'pointerArray'和'onesNeighbor'的声明能够准确地告诉你,但基本上,其中一个数组要么太小,要么是一个野指针 - 可能是后者。 – 2011-05-03 00:53:30
当前写入的COde永远不会到达内部循环,因为在第一次迭代开始时count将为2。 – Joe 2011-05-03 01:45:23