/* * This program checks the length of a tour. Give the points data file * name on the command line. */ #include #include typedef struct _point { float x, y, z; } point; float distance (point v[], int i, int j) { float dx, dy, dz; dx = v[i].x - v[j].x; dy = v[i].y - v[j].y; dz = v[i].z - v[j].z; return sqrt (dx*dx + dy*dy + dz*dz); } float tour_length (int tour[], point v[], int n) { int i, from, to; float sum; /* sum up distances between cities on the tour */ sum = 0; /* start at city 0 */ from = 0; for (i=1; i\n", argv[0]); exit (1); } f = fopen (argv[1], "r"); if (!f) { perror (argv[1]); exit (1); } fscanf (f, "%d\n", &n); for (i=0; i= 0 && tour[i] < n) present[i] = 1; else { fprintf (stderr, "index %d out of bounds!\n", tour[i]); exit (1); } } for (i=0; i