Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PosledenJazolSoX {
- public static void promeni(SLL<Integer> list,int x){
- SLLNode<Integer> tmp=list.getFirst();
- int position=0;
- int positionX=0;
- SLLNode<Integer> tmpX=null;
- while(tmp!=null){
- position++;
- if(tmp.element==x){
- tmpX=tmp;
- positionX=position;
- }
- tmp=tmp.succ;
- }
- list.insertFirst(tmpX.element);
- list.delete(tmpX);
- System.out.println(list);
- System.out.println(positionX);
- }
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- int n=in.nextInt();
- SLL<Integer> list=new SLL<>();
- for(int i=0;i<n;i++){
- list.insertLast(in.nextInt());
- }
- int x=in.nextInt();
- promeni(list,x);
- }
- }
Add Comment
Please, Sign In to add comment