How would I do this in C or is there another way to do this
How would I do this in C++? or is there another way to do this in Java with out using arrays? Given an arrangement of dominos, determine, whether or not it is a legal arrangement and return True or False accordingly. For example, this is an illegal arrangement [2 3][4 2][2 2][3 5] and this is a legal arrangement of Dominos. [2 3][3 5][5 4][4 5].
Solution
public class Domino {
private int lv;
private int rv;
public Domino(int lv, int rv) {
this.lv = lv;
this.rv = rv;
}
public int getLv() {
return lv;
}
public int getRv() {
return rv;
}
}
Domino[] dominos = new Domino[] {
new Domino(2, 3),
new Domino(3, 2),
new Domino(2, 5),
new Domino(2, 5)
};
Domino previous = null;
for (Domino current : dominos) {
if (previous != null) {
if (current.getLv() != previous.getRv()) {
throw new Exception(\"Illegal\");
}
}
previous = current;
}
