Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1.  
  2.     public static boolean P(Deque from, Deque to, Stack s) {
  3.         if (from.size() != 0) {
  4.             s.push(from.getFirst());
  5.             from.removeFirst();
  6.             return true;
  7.         } else
  8.             return false;
  9.     }
  10.  
  11.     public static boolean V(Deque from, Deque to, Stack s) {
  12.         if (s.size() != 0) {
  13.             to.addFirst(s.pop());
  14.             return true;
  15.         } else
  16.             return false;
  17.     }
  18.  
  19.     //请实现go函数
  20.     public static void go(Deque from, Deque to, Stack s) {
  21.  
  22.         if(to.size()==9)
  23.             answers++;
  24.  
  25.         Deque f = from.clone();
  26.         Deque t = to.clone();
  27.         Stack stack = s.clone();
  28.  
  29.         //if(stack.size()<4) {
  30.             if (P(from, to, s))// P V选择错误 则不继续迭代
  31.                 go(from, to, s);
  32.         //}
  33.  
  34.         if (V(f, t, stack))
  35.             go(f, t, stack);
  36.  
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement