I asked https://stackoverflow.com/questions/35579843/get-only-ring-nodes-from-a-diagram on stack overflow but there was no help at all. So I hope I get help from someone on here :)

I have a diagram that basically forms into a ring, each node is connected to another node. some nodes are part of the ring some are not. As the picture below shows, there is a ring of nodes (0,1,2,7,8,9). I want to get those nodes from the diagram and store them into a list.

enter image description here

Each node object contains details on the nodes it is connected to, so node 0, contains a list of connected nodes which basically has 1, and 9 in it.

I am trying to get the nodes within the ring, but the method I wrote does not work for all ring diagrams. Here is what I wrote that works on some diagrams

    private bool SetMainRingList(StructureFeature strct, StructureFeature root, List<StructureFeature> mainRing) {
        if ((strct.Equals(root) && mainRing.Contains(strct))) {
            return false;
        var children = strct.GetConnectedStructures();
        if ((children.Contains(root) && mainRing.Contains(strct))) {
            return false;
        foreach (var structureFeature in children) {
            if (mainRing.Contains(structureFeature)) {
                var strcture = mainRing.Find(x => x.Oid == structureFeature.Oid);
                if (strcture.ParentFeature == null)
                if (strcture.ParentFeature.Equals(root)) {
                    bool skip = false;
                    var crntChildren = strcture.GetConnectedStructures();
                    foreach (var childContainerse in crntChildren) {
                        if (!mainRing.Contains(childContainerse)) {
                            skip = true;
                    if (!skip)
                        return false;
            structureFeature.ParentFeature = strct;
            var leaf = SetMainRingList(structureFeature, root, mainRing);
            var exchangeSite = structureFeature as ExchangeStructure;
            if (leaf && ReferenceEquals(exchangeSite, null)) {
            } else {
                return false;
        return true;
  • 1
    What is an example of when it fails?
    – Hornbydd
    Feb 23, 2016 at 14:50
  • tbh there werent any differences except for an extra node, so it seems the direction is what made it work, when it truly souldnt have on the other one. I got the answer tho, its a lot simpler than I thought :)
    – ZZZ
    Feb 28, 2016 at 11:12

2 Answers 2


Try to detect first all loops you have in your diagram. store them in a list. The idea is to use them later as nodes : "one loop" = "one big node".

Try to define the left and right nodes (2 nodes) for each loop to connect with the rest. In your case the left node should be 9 and the right one is 2.

To make your life easier, I advise you to introduce links with fromNode and toNode. So you will have less information stored in nodes and your diagram will be correctly oriented, it's safe. One link connect two nodes and one node connect at least one link. The idea is to have a graph concept.

  • an ok answer, but not enough. no need for all of that when I can just get the bridges and eleminate them. Thanks for the help but I already got the answer.
    – ZZZ
    Feb 28, 2016 at 11:11

Here is the perfect answer to this problem, I find it faster, and easier to just look for the leafs instead of the ring. Simply, look for the bridges nodes that has one connection, remove them from the list, and update the list. carry on until there are no longer nodes that have 1 connection.

so in my diagram I have 4 leaf nodes that has 1 connection( 4, 5, 6, 10). after removing those and updating the list, I'll have one leaf left which (3). After removing it I will no longer have nodes with 1 connection, thus resulting in a list containing the ring.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.