Advertisement
Guest User

Untitled

a guest
May 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 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. boolean element;
  12.  
  13. public SLLNode(int id,int plata, SLLNode succ) {
  14. this.id = id;
  15. this.plata=plata;
  16. this.succ = succ;
  17. }
  18.  
  19.  
  20. }
  21.  
  22. class SLL {
  23. private SLLNode first;
  24. private Object tmp;
  25.  
  26. public SLL() {
  27. // Construct an empty SLL
  28. this.first = null;
  29. }
  30.  
  31. public void deleteList() {
  32. first = null;
  33. }
  34.  
  35. public int length() {
  36. int ret;
  37. if (first != null) {
  38. SLLNode tmp = first;
  39. ret = 1;
  40. while (tmp.succ != null) {
  41. tmp = tmp.succ;
  42. ret++;
  43. }
  44. return ret;
  45. } else
  46. return 0;
  47.  
  48. }
  49.  
  50.  
  51. public void insertFirst(int id, int plata) {
  52. SLLNode ins = new SLLNode(id,plata, first);
  53. first = ins;
  54. }
  55.  
  56. public void insertLast(int id,int plata) {
  57. if (first != null) {
  58. SLLNode tmp = first;
  59. while (tmp.succ != null)
  60. tmp = tmp.succ;
  61. SLLNode ins = new SLLNode(id, plata, null);
  62. tmp.succ = ins;
  63. } else {
  64. insertFirst(id,plata);
  65. }
  66. }
  67.  
  68. public SLLNode getFirst() {
  69. return first;
  70. }
  71.  
  72.  
  73. public SLL brisi_pomali_od(int iznos,SLL lista1) {
  74. // Vasiot kod tuka
  75. SLL lista3 = new SLL();
  76. SLLNode poc = lista1.getFirst();
  77.  
  78.  
  79. while(poc!=null){
  80. if(poc.plata >= iznos){
  81. lista3.insertLast(poc.id,poc.plata);
  82. poc=poc.succ;
  83. //lista3.insertLast(poc.succ);
  84. }
  85.  
  86. else{
  87. poc=poc.succ;
  88. }
  89. }
  90. if(lista3.getFirst()==null){
  91. System.out.println("nema");
  92. }
  93. return lista3;
  94. }
  95.  
  96. public SLL sortiraj_opagacki(SLL lista1) {
  97. // Vasiot kod tuka
  98. SLL lista = new SLL();
  99. SLLNode tmp = lista1.getFirst();
  100. SLLNode min;
  101.  
  102. while(lista1.getFirst()!=null){
  103. tmp=min=lista1.getFirst();
  104. while(tmp!=null){
  105. if(tmp.id > min.id){
  106. min=tmp;
  107.  
  108. }
  109. else {
  110. tmp=tmp.succ;
  111. // lista.insertLast(tmp.succ.id,tmp.succ.plata);
  112. }
  113. }
  114. lista.insertLast(min.id,min.plata);
  115. delete(min);
  116. }
  117. return lista;
  118. }
  119. public void pecati (SLL lista)
  120. {
  121. SLLNode p=lista.first;
  122. while(p!=null)
  123. {
  124. System.out.println(p.id+" "+p.plata);
  125. p=p.succ;
  126. }
  127. }
  128.  
  129. private void insertLast(SLLNode succ) {
  130. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  131. }
  132.  
  133. private void delete(SLLNode min) {
  134. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  135. }
  136.  
  137. }
  138. public class SLLKompanija {
  139. public static void main(String[] args) throws IOException {
  140.  
  141. SLL lista1 = new SLL();
  142. BufferedReader stdin = new BufferedReader(new InputStreamReader(
  143. System.in));
  144. String s = stdin.readLine();
  145. int N = Integer.parseInt(s);
  146.  
  147. for (int i = 0; i < N; i++) {
  148. s=stdin.readLine();
  149. String s1=stdin.readLine();
  150. lista1.insertLast(Integer.parseInt(s),Integer.parseInt(s1));
  151. }
  152. s = stdin.readLine();
  153.  
  154. lista1=lista1.brisi_pomali_od(Integer.parseInt(s),lista1);
  155. if(lista1!=null)
  156. {
  157. lista1=lista1.sortiraj_opagacki(lista1);
  158. lista1.pecati(lista1);
  159. }
  160.  
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement