Dijkstra's algorithm applies more to weighted paths and it sounds like the poster was wanting to find all paths, not just the shortest.
For this application, I'd build a graph (your application sounds like it wouldn't need to be directed) and use your favorite search method. It sounds like you want all paths, not just a guess at the shortest one, so use a simple recursive algorithm of your choice.
The only problem with this is if the graph can be cyclic.
With the connections:
While looking for a path from 1->4, you could have a cycle of 1 -> 2 -> 3 -> 1.
In that case, then I'd keep a stack as traversing the nodes. Here's a list with the steps for that graph and the resulting stack (sorry for the formatting - no table option):
current node (possible next nodes minus where we came from) [stack]
- 1 (2, 3) [1]
- 2 (3, 4) [1, 2]
- 3 (1) [1, 2, 3]
- 1 (2, 3) [1, 2, 3, 1] //error - duplicate number on the stack - cycle detected
- 3 () [1, 2, 3] // back-stepped to node three and popped 1 off the stack. No more nodes to explore from here
- 2 (4) [1, 2] // back-stepped to node 2 and popped 1 off the stack.
- 4 () [1, 2, 4] // Target node found - record stack for a path. No more nodes to explore from here
- 2 () [1, 2] //back-stepped to node 2 and popped 4 off the stack. No more nodes to explore from here
- 1 (3) [1] //back-stepped to node 1 and popped 2 off the stack.
- 3 (2) [1, 3]
- 2 (1, 4) [1, 3, 2]
- 1 (2, 3) [1, 3, 2, 1] //error - duplicate number on the stack - cycle detected
- 2 (4) [1, 3, 2] //back-stepped to node 2 and popped 1 off the stack
- 4 () [1, 3, 2, 4] Target node found - record stack for a path. No more nodes to explore from here
- 2 () [1, 3, 2] //back-stepped to node 2 and popped 4 off the stack. No more nodes
- 3 () [1, 3] // back-stepped to node 3 and popped 2 off the stack. No more nodes
- 1 () [1] // back-stepped to node 1 and popped 3 off the stack. No more nodes
- Done with 2 recorded paths of [1, 2, 4] and [1, 3, 2, 4]