When executing the program ensure that the working directory is the project root.
- Write a command line program in C++
- Do not use any additional libraries (std is fine of course)
- The program does the following:
- Read a file from disk like the one attached and generate a graph with nodes and edges as described in the file. "A<>B" means a bidirectional edge, "A->B" means a unidirectional edge.
- Find and remove any nodes that have exactly three incoming edges (so edges that are either directed at the node or bidirectional).
- Print all the remaining edges, similar to how the input file looks (no need to write it to a file, std::cout is fine).
- One edge per line.
- Supported forms:
A->B
(directed from A to B)A<>B
(bidirectional between A and B)A<-B
(equivalent toB->A
)
- Incoming edge count:
- Directed
A->B
counts as one incoming edge toB
. - Bidirectional
A<>B
counts as one incoming edge for bothA
andB
.
- Directed
- Removal:
- Nodes with exactly three incoming edges are removed.
- All incident edges to removed nodes are deleted.
- Output:
- Remaining edges are printed to stdout, one per line, using the same notation (
->
or<>
). - Each edge appears once (e.g.,
A<>B
printed in canonical order).
- Remaining edges are printed to stdout, one per line, using the same notation (
- Graph stores nodes in a hash map keyed by node label.
- Each node tracks inbound and outbound connections.
- Removal is done in two phases:
- Collect nodes with exactly three inbound edges.
- Remove them and clear them from other nodes.
- Printing ensures no duplicate edge output:
<>
edges printed once.->
edges printed once per direction.