Four people (John, Jane, Jack, Jason) were exploring a tunnel which only allowed one person to pass through each time. So they went in one after the other. Because the tunnel has a dead end, they had to walk back. Their families were waiting for them at the entrance of the tunnel. Who would their families see first, second, …, and the last? Choose a suitable data structure to simulate the tunnel, add the four people to the data structure, and then get them out using proper
Java
)Four people (John, Jane, Jack, Jason) were exploring a tunnel which only allowed one person to pass through
each time. So they went in one after the other. Because the tunnel has a dead end, they had to walk back. Their families
were waiting for them at the entrance of the tunnel. Who would their families see first, second, …, and the last? Choose a
suitable data structure to simulate the tunnel, add the four people to the data structure, and then get them out using proper
operations. You should write a Java method named enterTunnel to simulate the tunnel entering process, and a Java
method named leaveTunnel to simulate the process the four people get out of the tunnel. Then call the two methods in
the main method to test the two methods;
Step by step
Solved in 4 steps