I am amateur programmer learning how to program. I have never had any computer science courses so I have hard times with this trivial problem:
class Room {
String name;
ArrayList<Room> neighbors = new ArrayList<Room>();
// constructor with name
// getters
void addNeighbor(Room room) {
neighbors.add(room);
}
}
class Finder {
void findShortestPath(Room start, Room end) {
// ?
}
}
Every room has some neighbors. More then 4, so it's not like matrix oriented problem. You are given end room and you must find shortest path from the start room (comparing the names of the rooms). Result should be "way" like:
Start: Kitchen
End: Toilet
Path: Kitchen, Living Room, Corridor, Bedroom, Toilet
I think I must use some recursion for the rooms and I think I should save where I have already been in some stack. But I don't really know how to start.
Can some of you CS guys help me? Thanks