# 641. 设计循环双端队列

设计实现双端队列。

# 示例

struct MyCircularDeque {
    capacity: i32,
    members: Vec<i32>
}


/**
 * `&self` means the method takes an immutable reference.
 * If you need a mutable reference, change it to `&mut self` instead.
 */
impl MyCircularDeque {

    fn new(k: i32) -> Self {
        Self {
            capacity: k,
            members: Vec::new()
        }
    }

    fn insert_front(&mut self, value: i32) -> bool {
        if self.is_full() {
            return false
        }

        self.members.insert(0, value);
        true
    }

    fn insert_last(&mut self, value: i32) -> bool {
        if self.is_full() {
            return false
        }

        self.members.push(value);
        true
    }

    fn delete_front(&mut self) -> bool {
        if self.is_empty() {
            return false
        }

        self.members.remove(0);
        true
    }

    fn delete_last(&mut self) -> bool {
        if self.is_empty() {
            return false
        }

        self.members.pop();
        true
    }

    fn get_front(&self) -> i32 {
        self.members.first().copied().unwrap_or(-1)
    }

    fn get_rear(&self) -> i32 {
        self.members.last().copied().unwrap_or(-1)
    }

    fn is_empty(&self) -> bool {
        self.members.is_empty()
    }

    fn is_full(&self) -> bool {
        self.members.len() == self.capacity as usize
    }
}

# 参考