定义vector数组来存储
使用结构体+中间变量,或结构体的构造函数来实现
代码:
#include <vector>
#include <stdio.h>
using namespace std;
const int N = 10;
struct Node{
int v;
int w;
};
//构造函数存储图的信息
struct newNode{
int v,w;
newNode(int _v,int _w) : v(_v), w(_w) {} //构造函数
};
int main(){
Node temp;
temp.v = 3;
temp.w = 4;
vector<Node> Adj[N];
vector<newNode> newAdj[N];
Adj[1].push_back(temp);
printf("输出顶点编号及权值%d %d\n",Adj[1].front().v,Adj[1].front().w);
newAdj[2].push_back(newNode(5,6));
printf("输出顶点编号及权值%d %d",newAdj[2].front().v,newAdj[2].front().w);
}