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];         
}

iプログラムは、ゼロ未満になるとすぐにループから抜け出します。推測しなければならない場合、パス内の各ノードには、前のノードのインデックスへのリンクが含まれており、パス内の最後のノードが返さ-1れるか、その他の負の数が含まれていると言えます。

于 2013-01-17T22:39:23.937 に答える