Guest User

Untitled

a guest
Oct 27th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Iterator;
  5. import java.util.NoSuchElementException;
  6. import java.lang.Integer;
  7.  
  8. class SLL<E extends Number> implements Comparable<E>
  9. {
  10. private SLLNode<E> first;
  11. public SLL()
  12. {
  13. this.first = null;
  14. }
  15. public SLLNode<E> getFirst() {
  16. return first;
  17. }
  18. public void setFirst(SLLNode<E> first) {
  19. this.first = first;
  20. }
  21. public void insertFirst(E o)
  22. {
  23. SLLNode<E> ins = new SLLNode<E>(o, first);
  24. first = ins;
  25. }
  26. public void insertLast(E o)
  27. {
  28. if(first != null)
  29. {
  30. SLLNode<E> tmp = first;
  31. while(tmp.succ != null)
  32. tmp = tmp.succ;
  33. SLLNode<E> ins = new SLLNode<E>(o,null);
  34. tmp.succ = ins;
  35. }
  36. else
  37. {
  38. insertFirst(o);
  39. }
  40. }
  41. public SLL<E> joinLists(SLL<E> lista2)
  42. {
  43. SLL<E> rezultat = new SLL<E>();
  44. SLLNode<E> jazol1 = this.getFirst();
  45. SLLNode<E> jazol2 = lista2.getFirst();
  46. while(jazol1 != null && jazol2 !=null)
  47. {
  48. if(jazol1.getElement().compareTo(jazol2.getElement()) < 0)
  49. {
  50.  
  51. }
  52. }
  53.  
  54. }
  55. @Override
  56. public int compareTo(E o) {
  57. // TODO Auto-generated method stub
  58.  
  59. return 0;
  60. }
  61.  
  62.  
  63.  
  64. }
  65. class SLLNode<E>
  66. {
  67. protected E element;
  68. protected SLLNode<E> succ;
  69.  
  70. public E getElement() {
  71. return element;
  72. }
  73.  
  74. public void setElement(E element) {
  75. this.element = element;
  76. }
  77.  
  78. public SLLNode<E> getSucc() {
  79. return succ;
  80. }
  81.  
  82. public void setSucc(SLLNode<E> succ) {
  83. this.succ = succ;
  84. }
  85.  
  86. public SLLNode(E element, SLLNode<E> succ) {
  87. super();
  88. this.element = element;
  89. this.succ = succ;
  90. }
  91.  
  92.  
  93. }
  94. /*class JoinSortedLists<E> extends SLL<E>
  95. {
  96. public SLL<E> joinLists(SLL<E> lista2)
  97. {
  98. SLL<E> rezultat = new SLL<E>();
  99. SLLNode<E> jazol1 = this.getFirst();
  100. SLLNode<E> jazol2 = lista2.getFirst();
  101. while(jazol1 != null && jazol2 !=null)
  102. {
  103.  
  104. {
  105.  
  106. }
  107. }
  108.  
  109. }
  110. }*/
  111.  
  112.  
  113. public class SLLJoinLists {
  114. public static void main(String[] args) throws IOException {
  115. SLL<E> lista1 = new SLL<E>();
  116. SLL<E> lista2 = new SLL<E>();
  117. BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
  118. String s = stdin.readLine();
  119. int N = Integer.parseInt(s);
  120. s = stdin.readLine();
  121. String[] pomniza = s.split(" ");
  122. for (int i = 0; i < N; i++) {
  123. lista1.insertLast(Integer.parseInt(pomniza[i]));
  124. }
  125.  
  126. s = stdin.readLine();
  127. N = Integer.parseInt(s);
  128. s = stdin.readLine();
  129. pomniza = s.split(" ");
  130. for (int i = 0; i < N; i++) {
  131. lista2.insertLast(Integer.parseInt(pomniza[i]));
  132. }
  133.  
  134. // spoeni = lista1.joinLists(lista2);
  135. Iterator<Integer> it = spoeni.iterator();
  136. while (it.hasNext()) {
  137. System.out.print(it.next());
  138. if(it.hasNext())
  139. System.out.print(" ");
  140. }
  141. System.out.println();
  142. }
  143. }
Add Comment
Please, Sign In to add comment