I'm trying to build some network flow algorithms, and I need to represent edges in graph.
this is my Edge structure:
struct Edge{
int from, to, flow, cap;
Edge(int fromC, int toC, int flowC , int capC)
: from(fromC), to(toC), flow(flowC), cap(capC)
{};
};
then I have graph structure with adjacency list:
struct Graph {
int N;
vector<vector<Edge> > adjList; // list of neighbours
Graph(int n) { // constructor
N=n;
adjList.resize(n);
}
};
and then I have function to add edges to adjacency list:
void addEdge ( Graph &G, Edge &E)
{
G.adjList[E.from-1].push_back(E);
}
and I want to use this syntax:
Graph G = Graph(4); // creates graph with4 vertices
addEdge(G, new Edge(2, 4, 0, 4));
but this doesn`t work… I have to change function to:
void addEdge(Graph &G, Edge *E)
and then modify everything in function body…
My question is: Is there a way to use new in function call with references like ?:
addEdge(G, new Edge(2, 4, 0, 4));
Thank you for your answers. ( I'm new to C++, sorry if answer is obvious: No, you have to use pointers in signature & body... )