Martina312

Војска

Feb 4th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class DLLVojska {
  4.     public static DLLNode<Integer> findEl(DLL<Integer> list, int id){
  5.         DLLNode<Integer> tmp=list.getFirst();
  6.  
  7.         while(tmp.element!=id){
  8.             tmp=tmp.succ;
  9.         }
  10.         return tmp;
  11.     }
  12.     public static void vojska(DLL<Integer> list, int id1, int id2, int id3, int id4) {
  13.         DLLNode<Integer> tmp1=findEl(list,id1);
  14.         DLLNode<Integer> tmp2=findEl(list,id2);
  15.         DLLNode<Integer> tmp3=findEl(list,id3);
  16.         DLLNode<Integer> tmp4=findEl(list,id4);
  17.  
  18.         DLLNode<Integer> tmp3Copy=tmp3;
  19.         DLLNode<Integer> tmp4Copy=tmp4;
  20.         DLLNode<Integer> tmp1Copy=tmp1;
  21.         DLLNode<Integer> tmp2Copy=tmp2;
  22.         while(tmp3!=tmp4.succ){
  23.             list.insertBefore(tmp3.element,tmp1);
  24.             tmp3=tmp3.succ;
  25.         }
  26.         while(tmp1!=tmp2.succ){
  27.             list.insertBefore(tmp1.element,tmp3Copy);
  28.             tmp1=tmp1.succ;
  29.         }
  30.  
  31.         while(tmp3Copy!=tmp4Copy.succ){
  32.             list.delete(tmp3Copy);
  33.             tmp3Copy=tmp3Copy.succ;
  34.         }
  35.         while(tmp1Copy!=tmp2Copy.succ){
  36.             list.delete(tmp1Copy);
  37.             tmp1Copy=tmp1Copy.succ;
  38.         }
  39.         System.out.println(list);
  40.     }
  41.     public static void main(String[] args) {
  42.         Scanner in=new Scanner(System.in);
  43.  
  44.         int n=in.nextInt();
  45.         DLL<Integer> list=new DLL<>();
  46.         for(int i=0;i<n;i++){
  47.             list.insertLast(in.nextInt());
  48.         }
  49.  
  50.         int first1=in.nextInt();
  51.         int first2=in.nextInt();
  52.         int second1=in.nextInt();
  53.         int second2=in.nextInt();
  54.  
  55.         vojska(list,first1,first2,second1,second2);
  56.     }
  57. }
Add Comment
Please, Sign In to add comment