Question
With this code on C++: #include #include using namespace std; struct point { int x, y; }; int main() { point p; cout > p.x
With this code on C++:
#include
using namespace std;
struct point { int x, y; };
int main() { point p; cout > p.x >> p.y; int size = 10; point *arr = new point[size]; for(int i = 0; i > arr[i].x >> arr[i].y; } double *d = new double[size]; for(int i = 0; i d[j+1]) { ptemp.x = arr[j].x; ptemp.y = arr[j].y; arr[j].x = arr[j+1].x; arr[j+1].x = ptemp.x; arr[j].y = arr[j+1].y; arr[j+1].y = ptemp.y; dtemp = d[j]; d[j] = d[j+1]; d[j+1] = dtemp; } } } // print here cout
Add-on a function that moves the original point p.x and p.y to the next closest point once there the function uses the distance formula to find the closest point again to the new p.x and p.y. Do this until all ten points are hit.
Enter initial point: 0 0 Enter point 1: 11 Enter point 2: 5 2 Enter point 3: 53 Enter point 4: 1 3 Enter point 5: 1 6 Enter point 6: 8 3 Enter point 7: 9 2 Enter point 8: 9 7 Enter point 9: 1 6 Enter point 10: 4 4 Points from . in ascending order 4, 4 Process exited after 18.64 seconds with return ualue Press any key to continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started