I’m trying to make a constructor for a graph class that accepts a string as a
parameter and uses it to build the graph.
The string is formatted as follows: |vertex list|Edges list|
e.g. |1,2,3,4,15|(1->2),(3->2),(4->15)|
The idea is that the constructor will take the values from the string and then
know to perform the following actions (inserting the vertexes into the vertex list
and then inserting the edges into the edges list):
addVertex(1)
addVertex(2)
addVertex(3)
addVertex(4)
addVertex(15)
addEdge(1,2)
addEdge(3,2)
addEdge(4,15)
I would have just made a couple of “for” loops to scan the string, but I don’t know
what to do about double(or more) digit numbers. I’m starting to imagine all sorts
of seriously complicated for loops and I’m wondering if anyone here could share
with me any more intelligent ways to extract and use this data.
You can use a
stringstreamand use the stream extraction operator to get your integers.Since this is homework, I urge you to explore the possibilities and figure out the complete
code for yourself.