C++ calculate distance between structure of inputed and saved points and the origin, print out list according on distance
<p>In this task a simplified version of obstacles shall be modeled by points detected by an imaginary sensor system placed in the origin of a two dimensional local cartesian coordinate system.
Arbitrary many of such obstacles /points in front of a vehicle shall be possible to store in a list. This list shall be sorted by the Euclidian distance from the origin (see examples below).
(Hint: write a function to calculate the Euclidian distance d of two obstacles/points P1 and P2 with coordinates (x1,y1) and (x2,y2) by the formula: d=√(x1−x2)2+(y1−y2)2
To simply identify them each obstacle/point shall store a string ("A", "B", ... in example above), the distance and its coordinates (xi,yi). 
(Hint: give a type definition for a structure with these four data as components/variables of the structure.)
In a loop in function main arbitrary many of such obstacles/points shall be possible to be inputted and stored in a list. Afterwards the sorted by distance list shall be outputted. Beside the string, distance and coordinates in each output also the string of the nearest obstacle/point to it shall be computed and outputted additionaly (see example below).
(Hint: write a further function with a list of all obstacles/points as first and one obstacle/point as second parameter calculating the neareast other obstacle/point to it and returning it as pointer. Take care that an obstacle/point does not return and output distance 0 to itself, and that at least two obstacles/points need to exist; otherwise a null pointer nullptr shall be returned.)</p>

<p>I was able to create the structure function, the distance function and the list, unfortunately I'm not able to sort it and to use the function distance to calculate the actual distances.</p>

<p>Hope someone can help me!</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;cmath&gt;

using namespace std;

double distanceCalculate(double x1, double x2, double y1, double y2)
{
    double x = x1-x2;
    double y = y1-y2;
    double dist;
    dist = pow(x, 2) + pow(y , 2);
    dist = sqrt(dist);
    return dist;
}

struct point
{
    char name [1];
    double x, y, origin_distance ;
    struct point *next;
};

int main(void)
{
    int choice;
    struct point *head = nullptr, *newElement, *p ;
    do
    {
        cout &lt;&lt; "0 end"&lt;&lt; endl;
        cout &lt;&lt;"1 input point"&lt;&lt; endl;
        cout &lt;&lt;"2 print list of points" &lt;&lt; endl;
        cin &gt;&gt; choice;
        switch(choice)

        {
        case 1:
            newElement = new point;
            if (newElement == nullptr)
                cerr &lt;&lt; "Not enough free memory " &lt;&lt; endl;
            else
            {
                cout&lt;&lt; "Please enter point's name: ";
                cin&gt;&gt; newElement -&gt;name;
                cout &lt;&lt; "Please input value x:";
                cin &gt;&gt; newElement-&gt;x;
                cout &lt;&lt;"Please input value y:";
                cin &gt;&gt; newElement-&gt;y;
                newElement -&gt;next = head;
                head = newElement;
            }
            break;
        case 2:
            cout&lt;&lt; "Print list of points"&lt;&lt; endl;
            cout&lt;&lt; "name.\t x.\t y.\t" &lt;&lt; endl;
            p=head;
            while (p!= nullptr)
            {
                cout&lt;&lt; p-&gt;name&lt;&lt;"\t"&lt;&lt; p-&gt;x&lt;&lt;"\t" &lt;&lt; p-&gt;y &lt;&lt; "\t" &lt;&lt; endl;
                p=p-&gt;next;
            }
            break;


        }
    } while (choice !=0);
    return 0;
}
</code></pre>