I have set of line segments, containing only 2 points. I know their point numbers. some point numbers are appeared in many lines according to their connections. So, when joining some end points, I can get a closed polygon. So, I took a line segment and get an end point, and then find connection from that point. Then from those connections, I took subsequent connections respectively. Then, I try to find the other end point of my line segment. If that point is not inside any of the connections, I have to go further and look for their connections. And so on. This appear like a tree when i draft all the connection in a piece of paper.
I was trying to implement this but, i am not sure how should i handle this, effectiely. so, i am looking for some way.(i want to implement this in c++). also i heard depath first seearch method, i am not sure whether this methood can be solved my problem or not.

Also, I dont have any idea to implement even that to handle this type of case? Thank you in advance.

So, for example I have added below line list together with their point indices to get idea about m case. 
(Where First value = line number, second 2 values are the point indices)

```
0 - 9 11  
1 - 9 18  
2 - 9 16  
3 - 11 26  
4 - 11 45  
5 - 16 25
6 - 16 49  
7 - 18 26 
8 - 18 25  
9 - 18 21  
10 - 25 49  
11 - 26 45

```

So, assume I have started from the line `1`. That is I have started to find connected loops from point `9, 18`.
Then, could you please explain (step by step) how I can get the "closed loops" from that line.