循环内的代码不会打印

时间:2014-08-18 04:39:46

标签: c++ arrays graph cout

void Graph::sortW ()
{
    int length = vertices*vertices; 
    int array[length]; 
    for (int i = 0; i < length; i++)
    {
        array[i] = 0;
        cout << array[i]; // nothing prints 
    }
    cout << "i";     
    // convert to 1D array 
    for (int i = 0; i < vertices; i++) {
        for (int j = 0; j < vertices; j++) {
            array[i*vertices+j] = matrix[i][j]; 
            cout << array[i*vertices+j] << " "; // nothing prints 
        } 
    }
    cout << "j"; 
    qsort(array, length, sizeof(int), compare); 

    //  for (int i=0 ; i<25; i++)
    //      cout << array[i] << endl;  // only loop that prints?! 
}

我不知道为什么输出只是ij。在构造函数中调用Sort,如下所示:

// Sort weights using qsort 
sortW();    

有人有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我建议你放一个

cout << vertices;

在你的功能开始。我猜是vertices为零?