Polygon generation from a set of vertices?

Hello,

I am not sure if this is the right forum that I am posting in. Apologies if I put it in wrong place. Anyway, I am working on a small problem, where in I have to generate a small polygon based on the sides of it that I get as data. I have the information about the start and end points of the vertices of the polygon. While I could think of a solution, I am not sure if it is efficient enough. Here is what I thought:

Get the start point and end point of a random line, look for the start points of other lines, which has a match for the end point of the current line (let's assume that we just have one line with that condition) and connect that to the current line and so on .

There may be exceptions to this case but for time being, I am trying to figure out a solution for a simple problem. On the whole, I am new to this kind of concept and am looking for any best practices / efficinet algorithms that I can implement. If anyone of you can point me to them, I will be thankful.