Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1.     private static DLL<Integer> vojska(DLL<Integer> list, int a, int b, int c, int d) {
  2.  
  3.         DLLNode<Integer> current = list.getFirst();
  4.         DLLNode<Integer> startA = null, endB = null, startC = null, endD = null;
  5.  
  6.         while(current != null){
  7.  
  8.             if(current.element.equals(a)) {
  9.                 startA = current;
  10.             } else if (current.element.equals(b)) {
  11.                 endB = current;
  12.             } else if (current.element.equals(c)) {
  13.                 startC = current;
  14.             } else if (current.element.equals(d)) {
  15.                 endD = current;
  16.             }
  17.  
  18.             current = current.succ;
  19.         }
  20.  
  21.         DLLNode<Integer> startA_pred = startA.pred;
  22.         DLLNode<Integer> startC_pred = startC.pred;
  23.         DLLNode<Integer> endB_succ = endB.succ;
  24.         DLLNode<Integer> endD_succ = endD.succ;
  25.  
  26.         current = list.getFirst();
  27.  
  28.         while(current != null) {
  29.  
  30.             if(current.equals(startA)) {
  31.  
  32.                 if(startA.pred != null)
  33.                     startA_pred.succ = startC;
  34.                
  35.                 startC.pred = null;
  36.                 startC.pred = startA_pred;
  37.  
  38.                 endD.succ = endB_succ;
  39.                 endB_succ.pred = endD;
  40.             }
  41.  
  42.             if(current.equals(startC)) {
  43.  
  44.                if(endD.succ != null)
  45.                    endD_succ.pred = endB;
  46.  
  47.                 startC_pred.succ = startA;
  48.                 startA.pred = startC_pred;
  49.  
  50.                 endB.succ = null;
  51.             }
  52.  
  53.             current = current.succ;
  54.         }
  55.  
  56.         return list;
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement