Martina312

Последен јазол со информација Х

Feb 4th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PosledenJazolSoX {
  4.     public static void promeni(SLL<Integer> list,int x){
  5.         SLLNode<Integer> tmp=list.getFirst();
  6.         int position=0;
  7.         int positionX=0;
  8.         SLLNode<Integer> tmpX=null;
  9.         while(tmp!=null){
  10.             position++;
  11.             if(tmp.element==x){
  12.                 tmpX=tmp;
  13.                 positionX=position;
  14.             }
  15.             tmp=tmp.succ;
  16.         }
  17.         list.insertFirst(tmpX.element);
  18.         list.delete(tmpX);
  19.         System.out.println(list);
  20.         System.out.println(positionX);
  21.     }
  22.     public static void main(String[] args) {
  23.         Scanner in=new Scanner(System.in);
  24.         int n=in.nextInt();
  25.  
  26.         SLL<Integer> list=new SLL<>();
  27.         for(int i=0;i<n;i++){
  28.             list.insertLast(in.nextInt());
  29.         }
  30.         int x=in.nextInt();
  31.         promeni(list,x);
  32.     }
  33. }
Add Comment
Please, Sign In to add comment