Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5.  
  6.  
  7. class SLLNode {
  8. protected int id;
  9. protected int plata;
  10. protected SLLNode succ;
  11.  
  12. public SLLNode(int id,int plata, SLLNode succ) {
  13. this.id = id;
  14. this.plata=plata;
  15. this.succ = succ;
  16. }
  17.  
  18.  
  19. }
  20.  
  21. class SLL {
  22. private SLLNode first;
  23.  
  24. public SLL() {
  25. // Construct an empty SLL
  26. this.first = null;
  27. }
  28.  
  29. public void deleteList() {
  30. first = null;
  31. }
  32.  
  33. public int length() {
  34. int ret;
  35. if (first != null) {
  36. SLLNode tmp = first;
  37. ret = 1;
  38. while (tmp.succ != null) {
  39. tmp = tmp.succ;
  40. ret++;
  41. }
  42. return ret;
  43. } else
  44. return 0;
  45.  
  46. }
  47.  
  48.  
  49. public void insertFirst(int id, int plata) {
  50. SLLNode ins = new SLLNode(id,plata, first);
  51. first = ins;
  52. }
  53.  
  54. public void insertLast(int id,int plata) {
  55. if (first != null) {
  56. SLLNode tmp = first;
  57. while (tmp.succ != null)
  58. tmp = tmp.succ;
  59. SLLNode ins = new SLLNode(id, plata, null);
  60. tmp.succ = ins;
  61. } else {
  62. insertFirst(id,plata);
  63. }
  64. }
  65.  
  66. public SLLNode getFirst() {
  67. return first;
  68. }
  69.  
  70.  
  71. public SLL brisi_pomali_od(int iznos) {
  72. // Vasiot kod tuka
  73. SLLNode tmp = first;
  74. while(tmp.succ!=null) {
  75. if(tmp.succ.plata < iznos) {
  76. tmp.succ = tmp.succ.succ;
  77. }else {
  78. tmp = tmp.succ;
  79. }
  80. }
  81. tmp = first;
  82. if(tmp.plata < iznos) {
  83. first = first.succ;
  84. }
  85. return this;
  86. }
  87.  
  88. public SLL sortiraj_opagacki() {
  89. // Vasiot kod tuka
  90. SLLNode tmp = first;
  91. while(tmp.succ!=null) {
  92. SLLNode tmp1 = tmp.succ;
  93. while(tmp1!=null) {
  94. if(tmp.id < tmp1.id) {
  95. int id = tmp.id;
  96. int plata= tmp.plata;
  97. tmp.id = tmp1.id;
  98. tmp.plata = tmp1.plata;
  99. tmp1.id = id;
  100. tmp1.plata = plata;
  101. }
  102. tmp1 = tmp1.succ;
  103. }
  104. tmp = tmp.succ;
  105. }
  106. return this;
  107. }
  108. public void pecati (SLL lista)
  109. {
  110. SLLNode p=lista.first;
  111. if(p == null) {
  112. System.out.println("nema");
  113. }
  114. while(p!=null)
  115. {
  116. System.out.println(p.id+" "+p.plata);
  117. p=p.succ;
  118. }
  119. }
  120.  
  121. }
  122. public class SLLKompanija {
  123. public static void main(String[] args) throws IOException {
  124.  
  125. SLL lista1 = new SLL();
  126. BufferedReader stdin = new BufferedReader(new InputStreamReader(
  127. System.in));
  128. String s = stdin.readLine();
  129. int N = Integer.parseInt(s);
  130.  
  131. for (int i = 0; i < N; i++) {
  132. s=stdin.readLine();
  133. String s1=stdin.readLine();
  134. lista1.insertLast(Integer.parseInt(s),Integer.parseInt(s1));
  135. }
  136. s = stdin.readLine();
  137.  
  138. lista1=lista1.brisi_pomali_od(Integer.parseInt(s));
  139. if(lista1!=null)
  140. {
  141. lista1=lista1.sortiraj_opagacki();
  142. lista1.pecati(lista1);
  143. }
  144.  
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement