Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package a1;
- public class Permutation {
- private Lab[] labs;
- /**
- *
- * @param labs
- */
- public Permutation(Combination c) {
- this.labs = c.getCombination();
- c.getMask();
- }
- public boolean next() {
- boolean flag = true;
- Lab temp;
- int i;
- int j;
- int a = labs.length - 2;
- while (a >= 0 && labs[a].getLabel2() > labs[a + 1].getLabel2()) {
- if (labs.length > 1) {
- for (int iz = 0; iz < labs.length; iz++) {
- System.out.println(labs[iz].label2);
- System.exit(1);
- }
- }
- System.out.println(" stuck");
- a--;
- }
- if (a == -1) {
- return false;
- }
- if (a >= 0) {
- int b = labs.length - 1;
- while (labs[b].getLabel2() < labs[a].getLabel2()) {
- b--;
- }
- temp = labs[a];
- labs[a] = labs[b];
- labs[b] = temp;
- for (i = a + 1, j = labs.length - 1; i < j; i++, j--) {
- temp = labs[i];
- labs[i] = labs[j];
- labs[j] = temp;
- }
- }
- return flag;
- }
- public Lab[] getCurrent() {
- return labs;
- }
- public String displayPerm() {
- String value = "";
- for (int i = 0; i < labs.length; i++) {
- value += " " + labs[i].label2;
- }
- return value;
- }
- }
Add Comment
Please, Sign In to add comment