fork download
  1. //SLL.class
  2.  
  3. //package sll_testeing;
  4.  
  5. public class SLL<E> {
  6.  
  7. private SLLNode<E> first;
  8.  
  9. // SLLNode<E>(momentalen_element, sleden_element_na_momentalniot)
  10. public SLL() {
  11. this.first = null;
  12. }
  13.  
  14. public SLL(SLLNode<E> first) {
  15. this.first = first;
  16. }
  17.  
  18. public SLLNode<E> getFirst() {
  19. return this.first;
  20. }
  21.  
  22. public void insertFirst(E o) {
  23. SLLNode<E> ins = new SLLNode<E>(o, first);
  24. first = ins;
  25. }
  26.  
  27. public void insertLast(E o) {
  28. if (first != null) {
  29. // Prviot clen od listata go dava na tmp
  30. SLLNode<E> tmp = first;
  31. // Ja izminuva listata i koga ke dojde do null
  32. // ciklusot pagja i tmp e ima poslednata vrednost
  33. while (tmp.succ != null) {
  34. tmp = tmp.succ;
  35. }
  36. // Kreira nov link/jazol so noviot link i za sleden
  37. // go stava null zatoa sto go stava na kraj od listata
  38. SLLNode<E> ins = new SLLNode<E>(o, null);
  39. //sledniot na tmp t.e krajot go stava novokreiraniot el
  40. tmp.succ = ins;
  41. } else { // ako listata e prazna
  42. insertFirst(o); // go stava na pocetokot
  43. }
  44. }
  45.  
  46. public void insertAfter(E o, SLLNode<E> node) {
  47. if (node != null) {
  48. SLLNode<E> ins = new SLLNode<E>(o, node.succ);
  49. node.succ = ins;
  50. }
  51. }
  52.  
  53. public void insertBefore(E o, SLLNode<E> before) {
  54.  
  55. if (first != null) {
  56. SLLNode<E> tmp = first;
  57. if (first == before) {
  58. this.insertFirst(o);
  59. return;
  60. }
  61. while (tmp.succ != before) {
  62. tmp = tmp.succ;
  63. }
  64.  
  65. if (tmp.succ == before) {
  66. SLLNode<E> ins = new SLLNode<E>(o, before);
  67. tmp.succ = ins;
  68. } else {
  69. System.out.println("Ne moze da se otpecati\n");
  70. }
  71. } else {
  72. System.out.println("Listata e prazna!");
  73. }
  74. }
  75.  
  76. public void deleteFirst() {
  77.  
  78. if (first != null) {
  79. first = first.succ;
  80. } else {
  81. System.out.println("Listata e prazna!");
  82. }
  83. }
  84.  
  85. public void delete(E node) {
  86. if (first != null) {
  87. SLLNode<E> tmp = first;
  88.  
  89. if (first == node) {
  90. first = null;
  91. }
  92.  
  93. while (tmp.succ != node && tmp.succ.succ != null) {
  94. tmp.succ = tmp.succ.succ;
  95. }
  96.  
  97. if (tmp.succ == node) {
  98. tmp.succ = tmp.succ.succ;
  99. }
  100. } else {
  101. System.out.println("Listata e prazna!");
  102. }
  103. }
  104.  
  105. public int length() {
  106. int counter = 0;
  107. if (first != null) {
  108. counter++;
  109. SLLNode<E> tmp = first;
  110. while (tmp.succ != null) {
  111. tmp = tmp.succ;
  112. counter++;
  113. }
  114. }
  115. return counter;
  116. }
  117.  
  118. public void merge(SLL<E> to_be_merged) {
  119. if (first != null) {
  120. SLLNode<E> tmp = first;
  121. while (tmp.succ != null) {
  122. tmp = tmp.succ;
  123. }
  124. //SLLNode<E> ins = new SLLNode<E>(to_be_merged.getFirst(), )
  125. tmp.succ = to_be_merged.getFirst();
  126. } else {
  127. first = to_be_merged.getFirst();
  128. }
  129. }
  130.  
  131. public void mirror() {
  132. if(first != null)
  133. {
  134. SLLNode<E> tmp = first;
  135. SLLNode<E> newsucc = null;
  136. SLLNode<E> succ = null;
  137.  
  138. while(tmp != null)
  139. {
  140. succ = tmp.succ;
  141. tmp.succ = newsucc;
  142. newsucc = tmp;
  143. tmp = succ;
  144. }
  145. first = newsucc;
  146. }
  147. }
  148.  
  149. public void remove_duplicates()
  150. {
  151. if (first == null)
  152. return;
  153. SLLNode<E> tmp = first;
  154. while (tmp != null)
  155. {
  156. SLLNode<E> prevNode = tmp;
  157. SLLNode<E> currNode = tmp.succ;
  158. while (currNode != null)
  159. {
  160. //System.out.printf("Momentalen jazol vo vtoriot ciklus: %s\n", currNode.element.toString());
  161. if (tmp.element == currNode.element)
  162. {
  163. //Prebrisuvanje ako e pronajden ist element!
  164. //So sledniot na tmp. (pevNode.succ)
  165. prevNode.succ = currNode.succ;
  166. } else {
  167. prevNode = currNode; //updating prevNode in case of not a match
  168. }
  169. currNode = currNode.succ;
  170. }
  171. tmp = tmp.succ;
  172. }
  173.  
  174. }
  175.  
  176.  
  177. @Override
  178. public String toString() {
  179. String ret = new String();
  180. if (first != null) {
  181. SLLNode<E> tmp = first;
  182. ret += tmp + "-->";
  183. while (tmp.succ != null) {
  184.  
  185. tmp = tmp.succ;
  186. ret += tmp + "-->";
  187. }
  188. } else {
  189. System.out.println("Prazna lista");
  190. //System.exit(1);
  191. }
  192.  
  193. return ret;
  194.  
  195. }
  196.  
  197. }
  198.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class SLL is public, should be declared in a file named SLL.java
public class SLL<E> {
       ^
Main.java:7: error: cannot find symbol
    private SLLNode<E> first;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:14: error: cannot find symbol
    public SLL(SLLNode<E> first) {
               ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:18: error: cannot find symbol
    public SLLNode<E> getFirst() {
           ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:46: error: cannot find symbol
    public void insertAfter(E o, SLLNode<E> node) {
                                 ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:53: error: cannot find symbol
    public void insertBefore(E o, SLLNode<E> before) {
                                  ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:23: error: cannot find symbol
        SLLNode<E> ins = new SLLNode<E>(o, first);
        ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:23: error: cannot find symbol
        SLLNode<E> ins = new SLLNode<E>(o, first);
                             ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:30: error: cannot find symbol
            SLLNode<E> tmp = first;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:38: error: cannot find symbol
            SLLNode<E> ins = new SLLNode<E>(o, null);
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:38: error: cannot find symbol
            SLLNode<E> ins = new SLLNode<E>(o, null);
                                 ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:48: error: cannot find symbol
            SLLNode<E> ins = new SLLNode<E>(o, node.succ);
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:48: error: cannot find symbol
            SLLNode<E> ins = new SLLNode<E>(o, node.succ);
                                 ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:56: error: cannot find symbol
            SLLNode<E> tmp = first;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:66: error: cannot find symbol
                SLLNode<E> ins = new SLLNode<E>(o, before);
                ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:66: error: cannot find symbol
                SLLNode<E> ins = new SLLNode<E>(o, before);
                                     ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:87: error: cannot find symbol
            SLLNode<E> tmp = first;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:109: error: cannot find symbol
            SLLNode<E> tmp = first;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:120: error: cannot find symbol
            SLLNode<E> tmp = first;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:134: error: cannot find symbol
            SLLNode<E> tmp = first;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:135: error: cannot find symbol
            SLLNode<E> newsucc = null;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:136: error: cannot find symbol
            SLLNode<E> succ = null;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:153: error: cannot find symbol
        SLLNode<E> tmp = first;
        ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:156: error: cannot find symbol
            SLLNode<E> prevNode = tmp;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:157: error: cannot find symbol
            SLLNode<E> currNode = tmp.succ;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
Main.java:181: error: cannot find symbol
            SLLNode<E> tmp = first;
            ^
  symbol:   class SLLNode
  location: class SLL<E>
  where E is a type-variable:
    E extends Object declared in class SLL
26 errors
stdout
Standard output is empty