Question 16
stations is a list that contains the sequence of stations visited by a train from the "Trains" dataset. Each element in stations is a pair: [Name, Distance], the first entry is the name of the station, while the second entry is the distance of this station from the first station in the list.
maxDist is a procedure that accepts stations as a parameter and returns the names of a pair of consecutive stations which have the longest distance between them on this route. Complete the following procedure.
1 Procedure maxDist(stations) 2 pair = ["None", "None"] 3 max = 0, diff = 0 4 prev = first(stations) 5 foreach x in rest(stations){ 6 diff = last(x) - last(prev) 7 ************************* 8 * Fill the code * 9 *************************10 prev = x11 }12 return(pair)13 End maxDistBased on the above data, answer the given subquestions.
There may be multiple pairs having the same maximum distance. If we wish to find a pair of stations closest to the first station in the list, which of the following is the correct code fragment?