Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. if (ra == ReorganizingAlgorithm.COUNT) {
  2.  
  3. ListItem<T> item = head;
  4. item.counter = 0;
  5. while (item.next != null) {
  6. if (predicate.test(item.next.key)) {
  7. item.next.counter++;
  8. }
  9.  
  10. // wenn pos 1, groeßte ist
  11.  
  12. if (head.next.counter > head.counter) {
  13.  
  14. //System.out.println("hier");
  15.  
  16. ListItem<T> tmpItem = head;
  17. ListItem<T> tmpNext = head.next;
  18.  
  19. tmpItem.next = head.next.next;
  20. tmpNext.next = head;
  21. head = tmpNext;
  22. break;
  23.  
  24.  
  25.  
  26. }
  27. item = item.next;
  28. } // end while
  29.  
  30. } //------------------------------------------
  31. // if (this.ra == ReorganizingAlgorithm.COUNT) {
  32. // //checking if list is empty
  33. // if(head == null) {
  34. // return null;
  35. // } else {
  36. //
  37. // // creating four pointers
  38. // ListItem<T> c = head;
  39. // ListItem<T> z = head;
  40. // ListItem<T> p = head;
  41. // ListItem<T> y = head;
  42. //
  43. // //lfc=lowestFoundCounter= the value of the lowest found counter so far
  44. // int lfc = p.counter;
  45. //
  46. // //asc=amountOfSameCounters= the amount of elements found with the same counter as the current element
  47. // int asc = 1;
  48. //
  49. //
  50. // //checking if first item is the searched one
  51. // if(predicate.test(p.key)) {
  52. // p.counter++;
  53. // return head.key;
  54. // }
  55. // //checking if next item is the searched one
  56. // if(predicate.test(p.next.key)) {
  57. // p.next.counter++;
  58. // //marking current(=c) element
  59. // c = p.next;
  60. //
  61. // //if item has to be swapped
  62. // if(lfc < p.next.counter) {
  63. // while(asc > 0) {
  64. //
  65. // //bringing pointers to correct position
  66. // y.next=c;
  67. // p.next=c;
  68. // z=c;
  69. //
  70. // //swapping places
  71. // p.next = p.next.next;
  72. // z.next = z.next.next;
  73. // p.next.next=z;
  74. // z.next=p;
  75. // asc--;
  76. // }
  77. // }
  78. // }
  79. //
  80. // //if counters of current and next item are the same, increase asc.
  81. // if (p.counter == p.next.counter) {
  82. // asc++;
  83. // }
  84. //
  85. // else {
  86. // asc=1;
  87. // }
  88. // p = p.next;
  89. // }
  90. //
  91. // return null;
  92. //
  93. // }
  94. //
  95. //
  96. // return null;
  97. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement