通过相邻顶点实现图形 美好的一天。我有一个通过相邻顶点的图形的任务写函数 - 添加一个顶点,添加边,添加边的权重。 移除顶点,移除边缘,移除边缘重量 找邻近或肋骨。 我写了我所知道的,但标志在哪里 - " ??????"那里我不知道怎么办,所以我想请你帮忙
// //头
#pragma once
#include <vector>
struct Edge
{
int mV;
int mW;
};
struct Node
{
int mEnd;
float mWeight;
};
using AjacencyList = std::vector<Node>;
class Graph
{
public:
Graph(int key, bool digraph);
void insert(int key);
void insertEdge(Edge edge);
void remove(int key);
void removeEdge(Edge edge);
bool relatedEdge(Edge edge1, Edge edge2);
bool directed();
private:
bool mDigraph = false;
AjacencyList mAdjacencyLists;
};
// CPP //
#include "stdafx.h"
#include "Graph.h"
#include <iostream>
Graph::Graph(int key, bool digraph)
: mDigraph(digraph)
, mAdjacencyLists(key)
{
}
void Graph::insert(int key)
{
if (mAdjacencyLists[key].mEnd == false)
mAdjacencyLists[key].mEnd = true;
else
std::cout << "Sorry" << "\n";
}
void Graph::insertEdge(Edge edge)
{
if ((mAdjacencyLists[edge.mV].mEnd == true) &&
(mAdjacencyLists[edge.mW].mEnd == true)
&& (mAdjacencyLists[edge.mV].mWeight == false) &&
(mAdjacencyLists[edge.mW].mEnd == false) && (edge.mV !=
edge.mW))
{
Node node;
mAdjacencyLists[edge.mV] = node.mEnd; // ???
mAdjacencyLists[edge.mW] = node.mWeight; //???
}
}
void Graph::remove(int key)
{
if (mAdjacencyLists[key].mEnd == true)
{
mAdjacencyLists[key].mEnd = false;
for (int i = 1; i < 1000; ++i)
{
if (mAdjacencyLists[i].mEnd == 1)
--mEnd; // ????????
}
}
else
std::cout << "Error" <<"\n";
}
void Graph::removeEdge(Edge edge)
{
if ((mAdjacencyLists[edge.mV].mEnd == true) &&
(mAdjacencyLists[edge.mW].mEnd == true) &&
(mAdjacencyLists[edge.mV].mWeight == true)
&& (mAdjacencyLists[edge.mW].mEnd == true) &&
(edge.mV != edge.mW))
{
// ???
}
}
bool Graph::relatedEdge(Edge edge1, Edge edge2)
{
if (edge1.mW == edge2.mW)
return true;
return false;
}
bool Graph::directed()
{
return mDigraph;
}