Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Main{
- public static Scanner sc=new Scanner(System.in);
- public static class Node
- {
- int data;
- Node next;
- Node(int value)
- {
- this.data=value;
- this.next=null;
- }
- }
- public static void fun()
- {
- int n=sc.nextInt();
- int pos=sc.nextInt();
- Node head=null;
- Node last=null;
- for(int i=0;i<n;i++)
- {
- int v=sc.nextInt();
- if(head==null)
- {
- head=new Node(v);
- last=head;
- } else
- {
- last.next=new Node(v);
- last=last.next;
- }
- }
- int newpos=n-pos+1;
- if(newpos==1)
- {
- Node prev=head;
- head=head.next;
- prev=null;
- } else
- {
- Node prev=head;
- for(int i=2;i<newpos;i++)
- {
- prev=prev.next;
- }
- Node target=prev.next;
- prev.next=target.next;
- target=null;
- }
- Node n1=head;
- while(n1!=null)
- {
- System.out.print(n1.data+" ");
- n1=n1.next;
- }
- return ;
- }
- public static void main(String[] args)
- {
- int tc=sc.nextInt();
- for(int i=0;i<tc;i++)
- {
- fun();
- System.out.println();
- }
- return ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement