Advertisement
Martina312

PomaliOdX

Feb 3rd, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PomaliOdX<E>{
  4. public void change(SLL<Integer> list, int x){
  5. SLLNode<Integer> tmp=list.getFirst();
  6. SLLNode<Integer> before=null;
  7.  
  8. while(tmp!=null){
  9. if(tmp.element>=x){
  10. before=tmp;
  11. break;
  12. }
  13. tmp=tmp.succ;
  14. }
  15. tmp=tmp.succ;
  16. while(tmp!=null){
  17. if(tmp.element<x){
  18. list.insertBefore(tmp.element, before);
  19. SLLNode<Integer> kopija=tmp;
  20. list.delete(tmp);
  21. tmp=kopija.succ;
  22. }
  23. else
  24. tmp=tmp.succ;
  25. }
  26. System.out.println(list);
  27. }
  28.  
  29.  
  30. public static void main(String[] args) {
  31. Scanner in=new Scanner(System.in);
  32. int x=3;
  33. SLL<Integer> list=new SLL<>();
  34. for(int i=0;i<6;i++){
  35. list.insertLast(in.nextInt());
  36. }
  37.  
  38. PomaliOdX<Integer> hm=new PomaliOdX<>();
  39. hm.change(list,x);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement