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