Question: Suppose you have two rail-roads modeled as singly linked list as shown in the figure below. The nodes are stations with names (A, B, etc)

 Suppose you have two rail-roads modeled as singly linked list as

Suppose you have two rail-roads modeled as singly linked list as shown in the figure below. The nodes are stations with names (A, B, etc) and the links are direct path between the two stations. Write a complete Java program to find if these two rail-roads meet or not. If they happen to meet, then return the first common node where the meeting happens. If the rail-roads do not meet, then return null. As shown in the figure below, the two rail-roads meet at station D since the 4th station in the first rail-road is same as the 3rd station in the second rail-road. So, station D should be returned. Don't use Java's built-in HashMap for implementation.- 2 3 You can start with the following code: // see class LLStringNode in page 106 for the full implementation of linked list node.4 class StationNode d private String info;e private StationNode link;* public class RailRoad f* // Implement this method public StationNode find!stCommon Node(StationNode road!, Station Node road2)( el You can test your find1stCommonNode method with the following scenarios: 1. Both rail-roads have same length.- 2. The rail roads meet at the first station or last station. 3, Rail roads do not meet at all

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!