Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DLLVojska {
- public static DLLNode<Integer> findEl(DLL<Integer> list, int id){
- DLLNode<Integer> tmp=list.getFirst();
- while(tmp.element!=id){
- tmp=tmp.succ;
- }
- return tmp;
- }
- public static void vojska(DLL<Integer> list, int id1, int id2, int id3, int id4) {
- DLLNode<Integer> tmp1=findEl(list,id1);
- DLLNode<Integer> tmp2=findEl(list,id2);
- DLLNode<Integer> tmp3=findEl(list,id3);
- DLLNode<Integer> tmp4=findEl(list,id4);
- DLLNode<Integer> tmp3Copy=tmp3;
- DLLNode<Integer> tmp4Copy=tmp4;
- DLLNode<Integer> tmp1Copy=tmp1;
- DLLNode<Integer> tmp2Copy=tmp2;
- while(tmp3!=tmp4.succ){
- list.insertBefore(tmp3.element,tmp1);
- tmp3=tmp3.succ;
- }
- while(tmp1!=tmp2.succ){
- list.insertBefore(tmp1.element,tmp3Copy);
- tmp1=tmp1.succ;
- }
- while(tmp3Copy!=tmp4Copy.succ){
- list.delete(tmp3Copy);
- tmp3Copy=tmp3Copy.succ;
- }
- while(tmp1Copy!=tmp2Copy.succ){
- list.delete(tmp1Copy);
- tmp1Copy=tmp1Copy.succ;
- }
- System.out.println(list);
- }
- public static void main(String[] args) {
- Scanner in=new Scanner(System.in);
- int n=in.nextInt();
- DLL<Integer> list=new DLL<>();
- for(int i=0;i<n;i++){
- list.insertLast(in.nextInt());
- }
- int first1=in.nextInt();
- int first2=in.nextInt();
- int second1=in.nextInt();
- int second2=in.nextInt();
- vojska(list,first1,first2,second1,second2);
- }
- }
Add Comment
Please, Sign In to add comment