Guest User

Untitled

a guest
Jan 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package a1;
  2.  
  3. public class Permutation {
  4.  
  5. private Lab[] labs;
  6.  
  7. /**
  8. *
  9. * @param labs
  10. */
  11. public Permutation(Combination c) {
  12. this.labs = c.getCombination();
  13.  
  14. c.getMask();
  15.  
  16. }
  17.  
  18. public boolean next() {
  19. boolean flag = true;
  20. Lab temp;
  21. int i;
  22. int j;
  23.  
  24. int a = labs.length - 2;
  25.  
  26. while (a >= 0 && labs[a].getLabel2() > labs[a + 1].getLabel2()) {
  27. if (labs.length > 1) {
  28. for (int iz = 0; iz < labs.length; iz++) {
  29. System.out.println(labs[iz].label2);
  30. System.exit(1);
  31. }
  32. }
  33. System.out.println(" stuck");
  34. a--;
  35.  
  36. }
  37. if (a == -1) {
  38. return false;
  39. }
  40. if (a >= 0) {
  41. int b = labs.length - 1;
  42.  
  43. while (labs[b].getLabel2() < labs[a].getLabel2()) {
  44.  
  45. b--;
  46. }
  47. temp = labs[a];
  48. labs[a] = labs[b];
  49. labs[b] = temp;
  50. for (i = a + 1, j = labs.length - 1; i < j; i++, j--) {
  51. temp = labs[i];
  52. labs[i] = labs[j];
  53. labs[j] = temp;
  54. }
  55.  
  56. }
  57.  
  58. return flag;
  59. }
  60.  
  61. public Lab[] getCurrent() {
  62. return labs;
  63. }
  64.  
  65. public String displayPerm() {
  66. String value = "";
  67.  
  68. for (int i = 0; i < labs.length; i++) {
  69. value += " " + labs[i].label2;
  70. }
  71. return value;
  72. }
  73. }
Add Comment
Please, Sign In to add comment