0

看看下面的代码一次,通过澄清我的疑问来帮助我。我已经对我有疑问的每一行发表了我的疑问。此外,它是一个巨大代码的一部分。所以请忽略变量声明和所有。

整个代码运行完美,编译时没有错误。

double Graph::Dijkstra( path_t& path )
{
    int* paths = new int[_size];
    double min = dijkstra(paths); // **is a function call or not? bcz i didn't found any function in the code**
   if(min < 0) { delete[] paths; return -1;}


    int i = _size - 1;  
    while(i>=0)
    {       
        path.push(i);   // **when will the program come out of this while loop, i'm wondering how does it breaks?** 
        i=paths[i];         
    }

    path.push(0); 

    delete[] paths;
    return min;
}

此处提供了完整的编码。

4

1 回答 1

0
 double min = dijkstra(paths); // **is a function call or not? bcz i didn't found any function in the code**

几乎可以肯定是。但是,它可以是自由函数、成员函数、宏调用的函数或其他东西。没有看到其余的代码,我们只能猜测。

while(i>=0)
{       
    path.push(i);   // **when will the program come out of this while loop, i'm wondering how does it breaks?** 
    i=paths[i];         
}

The program will come out of the loop as a soon as i is less than zero. If I had to guess, I'd say the each node in the path contains a link to the previous node's index with the last node in a path returning -1 or some other negative number.

于 2013-01-17T22:39:23.937 回答