#include<iostream>
#include<string>
#include<fstream>
using namespace std;
typedef struct ENnode {
int adjvex;
int weight;
ENode* nextarc;
}ENode;
typedef struct Vnode
{
int vertex;
ENode* firstarc;
int edge;
}VNode;
class Graph
{
public:
virtual void CreateAdj(int v, int e, int weight) = 0;
//virtual void FindEdge(int x) = 0;//輸出X點的鄰接表
};
class DirectedGraph :public Graph
{
private:
VNode* vertex;
int v, e;
public:
DirectedGraph(int a,int b)
{
vertex = new VNode;
int j = 0;
for (int i = 0; i < a; i++)
{
j = i + 1;
vertex[i].vertex = j;
vertex[i].edge = 0;
vertex[i].firstarc = new ENode;
vertex[i].firstarc->adjvex = 0;
vertex[i].firstarc->nextarc = NULL;
vertex[i].firstarc->weight = 0;
}
v = a;
e = b;
}
void CreateAdj(int v1, int v2, int weight)
{
ENode* temp = new ENode;
temp->adjvex = v2;
temp->weight = weight;
temp->nextarc = NULL;
temp->nextarc = vertex[v - 1].firstarc->nextarc;
vertex[v - 1].firstarc->nextarc = temp;
vertex[v - 1].edge++;
}
void DispAdj()
{
int i;
ENode* temp;
for (i = 0; i < vertex->edge; i++)
{
temp = vertex[i].firstarc;
printf("%3d: ", i);
while (temp != NULL)
{
printf("%3d[%d]->", temp->adjvex, temp->weight);
temp = temp->nextarc;
}
}
}
};
int main()
{
DirectedGraph temp(3, 4);
int v, e, w,i=0;
while (i < 5)
{
cin >> v >> e >> w;
temp.CreateAdj(v, e, w);
i++;
}
temp.DispAdj();
}
當我測驗時輸入v e w為1 2 5(測驗資料)會出現如下錯誤


求大神幫助啊!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/236835.html
標籤:新手樂園
