01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package algs13.xbacktrack.xframework;
import algs13.Stack;
import java.util.Iterator;
/**
* A successful solution to a backtracking problem. The choices
* are provided in a stack, in reverse order from which they were
* determined.
*
* @param <T> The type of the choices made in the backtracking problem.
*/
public final class XBacktrackSuccess<T> implements XBacktrackResult {
private final Stack<T> choices;
public XBacktrackSuccess(Stack<T> choices) {
this.choices = choices;
}
@Override
public boolean isSuccess() {
return true;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Solution: [ ");
Iterator<T> it = choices.iterator();
while(it.hasNext()) {
builder.append(it.next());
if(it.hasNext()) {
builder.append(", ");
}
}
builder.append(" ]");
return builder.toString();
}
}
|