package leetcode;

/**
 * https://leetcode.com/problems/design-circular-deque/
 */
public class Problem641 {
    private static class MyCircularDeque {

        /** Initialize your data structure here. Set the size of the deque to be k. */
        public MyCircularDeque(int k) {
            // TODO
        }

        /** Adds an item at the front of Deque. Return true if the operation is successful. */
        public boolean insertFront(int value) {
            // TODO
            return false;
        }

        /** Adds an item at the rear of Deque. Return true if the operation is successful. */
        public boolean insertLast(int value) {
            // TODO
            return false;
        }

        /** Deletes an item from the front of Deque. Return true if the operation is successful. */
        public boolean deleteFront() {
            // TODO
            return false;
        }

        /** Deletes an item from the rear of Deque. Return true if the operation is successful. */
        public boolean deleteLast() {
            // TODO
            return false;
        }

        /** Get the front item from the deque. */
        public int getFront() {
            // TODO
            return 0;
        }

        /** Get the last item from the deque. */
        public int getRear() {
            // TODO
            return 0;
        }

        /** Checks whether the circular deque is empty or not. */
        public boolean isEmpty() {
            // TODO
            return false;
        }

        /** Checks whether the circular deque is full or not. */
        public boolean isFull() {
            // TODO
            return false;
        }
    }

    public static void main(String[] args) {
        MyCircularDeque deque = new MyCircularDeque(3);
        System.out.println(deque.insertLast(1)); // return true
        System.out.println(deque.insertLast(2)); // return true
        System.out.println(deque.insertFront(3)); // return true
        System.out.println(deque.insertFront(4)); // return false, the queue is full
        System.out.println(deque.getRear()); // return 32
        System.out.println(deque.isFull()); // return true
        System.out.println(deque.deleteLast()); // return true
        System.out.println(deque.insertFront(4)); // return true
        System.out.println(deque.getFront()); // return 4
    }
}

@@ -12,16 +12,46 @@
 tcode;%0A%0A
+import java.util.LinkedList;%0A%0A
 /**%0A * h
@@ -174,16 +174,118 @@
 rDeque %7B
+%0A        private final int size;%0A        private final LinkedList%3CInteger%3E deque = new LinkedList%3C%3E();
 %0A%0A      
@@ -409,39 +409,41 @@
 ) %7B%0A            
-// TODO
+size = k;
 %0A        %7D%0A%0A    
@@ -589,32 +589,44 @@
             
-// TODO%0A
+if (isFull()) %7B%0A    
             
@@ -631,32 +631,106 @@
   return false;%0A
+            %7D%0A            deque.addFirst(value);%0A            return true;%0A
         %7D%0A%0A     
@@ -873,32 +873,44 @@
             
-// TODO%0A
+if (isFull()) %7B%0A    
             
@@ -915,32 +915,105 @@
   return false;%0A
+            %7D%0A            deque.addLast(value);%0A            return true;%0A
         %7D%0A%0A     
@@ -1154,32 +1154,45 @@
             
-// TODO%0A
+if (isEmpty()) %7B%0A    
             
@@ -1197,32 +1197,104 @@
   return false;%0A
+            %7D%0A            deque.removeFirst();%0A            return true;%0A
         %7D%0A%0A     
@@ -1433,32 +1433,45 @@
             
-// TODO%0A
+if (isEmpty()) %7B%0A    
             
@@ -1476,32 +1476,103 @@
   return false;%0A
+            %7D%0A            deque.removeLast();%0A            return true;%0A
         %7D%0A%0A     
@@ -1652,39 +1652,89 @@
 ) %7B%0A            
-// TODO
+if (isEmpty()) %7B%0A                return -1;%0A            %7D
 %0A            ret
@@ -1729,33 +1729,48 @@
          return 
-0
+deque.getFirst()
 ;%0A        %7D%0A%0A   
@@ -1862,36 +1862,100 @@
     
-// TODO%0A            return 0
+if (isEmpty()) %7B%0A                return -1;%0A            %7D%0A            return deque.getLast()
 ;%0A  
@@ -2080,40 +2080,30 @@
     
-// TODO%0A            return false
+return deque.isEmpty()
 ;%0A  
@@ -2226,740 +2226,46 @@
     
-// TODO%0A            return false;%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        MyCircularDeque deque = new MyCircularDeque(3);%0A        System.out.println(deque.insertLast(1)); // return true%0A        System.out.println(deque.insertLast(2)); // return true%0A        System.out.println(deque.insertFront(3)); // return true%0A        System.out.println(deque.insertFront(4)); // return false, the queue is full%0A        System.out.println(deque.getRear()); // return 32%0A        System.out.println(deque.isFull()); // return true%0A        System.out.println(deque.deleteLast()); // return true%0A        System.out.println(deque.insertFront(4)); // return true%0A        System.out.println(deque.getFront()); // return 4
+return deque.size() == size;%0A        %7D
 %0A   

Solve problem 641