Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static DLL<Integer> vojska(DLL<Integer> list, int a, int b, int c, int d) {
- DLLNode<Integer> current = list.getFirst();
- DLLNode<Integer> startA = null, endB = null, startC = null, endD = null;
- while(current != null){
- if(current.element.equals(a)) {
- startA = current;
- } else if (current.element.equals(b)) {
- endB = current;
- } else if (current.element.equals(c)) {
- startC = current;
- } else if (current.element.equals(d)) {
- endD = current;
- }
- current = current.succ;
- }
- DLLNode<Integer> startA_pred = startA.pred;
- DLLNode<Integer> startC_pred = startC.pred;
- DLLNode<Integer> endB_succ = endB.succ;
- DLLNode<Integer> endD_succ = endD.succ;
- current = list.getFirst();
- while(current != null) {
- if(current.equals(startA)) {
- if(startA.pred != null)
- startA_pred.succ = startC;
- startC.pred = null;
- startC.pred = startA_pred;
- endD.succ = endB_succ;
- endB_succ.pred = endD;
- }
- if(current.equals(startC)) {
- if(endD.succ != null)
- endD_succ.pred = endB;
- startC_pred.succ = startA;
- startA.pred = startC_pred;
- endB.succ = null;
- }
- current = current.succ;
- }
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement