如何解决循环内函数调用的输出不符合预期
#include <iostream>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <memory>
#include "C:\Users\HP\Documents\Dreyfus-Wagner\Dijkstra.h"
using namespace std;
#define MAX 100001
#define pir pair<int,int>
#define pbd(x) push_back(x)
using namespace std;
#define MAX 100001
#define pir pair<int,int>
#define pbd(x) push_back(x)
struct Out
{
int *p;
};
vector<pir> Graph[MAX];
int main()
{
int nodes1,edges1,starting1;
// create graph
cout << "Enter the number of vertices and edges: ";
cin >> nodes1 >> edges1;
cout << "Enter the edges with weigth: <source> <destination> <weigth>: \n";
int u1,v1,w1;
struct Out output[nodes1];
int adjMatrix[nodes1][nodes1];
for (int i = 0; i < edges1; i++)
{
cin >> u1 >> v1 >> w1;
Graph[u1].pbd(pir(v1,w1));
Graph[v1].pbd(pir(u1,w1)); // for undirected
}
cout << "Enter the source node: ";
cin >> starting1;
for (int i = 1; i <= nodes1; i++)
{
output[i].p = Djiktra(nodes1,i,Graph);
}
for (int j = 1; j <= nodes1; j++)
{
for (int i = 1; i <= nodes1; i++)
{
cout << "*(p + " << i << ") : ";
cout << *(output[j].p + i) << endl;
;
}
cout << " " << endl;
}
}
https://github.com/SpecFlowOSS/SpecFlow/issues/1733
如果我们调用函数的单个实例,它将给出正确的输出。 注意:Djiktra函数存储在标头中引用的另一个文件中。这个想法是找到每个节点的最短元素长度
有人可以解释为什么在for循环内调用时输出不正确吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。