Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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