problem0641

package
v0.0.0-...-899dd15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2020 License: MIT Imports: 0 Imported by: 0

README

641. Design Circular Deque

题目

Design your implementation of the circular double-ended queue (deque).

Your implementation should support following operations:

  • MyCircularDeque(k): Constructor, set the size of the deque to be k.
  • insertFront(): Adds an item at the front of Deque. Return true if the operation is successful.
  • insertLast(): Adds an item at the rear of Deque. Return true if the operation is successful.
  • deleteFront(): Deletes an item from the front of Deque. Return true if the operation is successful.
  • deleteLast(): Deletes an item from the rear of Deque. Return true if the operation is successful.
  • getFront(): Gets the front item from the Deque. If the deque is empty, return -1.
  • getRear(): Gets the last item from Deque. If the deque is empty, return -1.
  • isEmpty(): Checks whether Deque is empty or not.
  • isFull(): Checks whether Deque is full or not.

Example:

MyCircularDeque circularDeque = new MycircularDeque(3); // set the size to be 3
circularDeque.insertLast(1); // return true
circularDeque.insertLast(2); // return true
circularDeque.insertFront(3); // return true
circularDeque.insertFront(4); // return false, the queue is full
circularDeque.getRear(); // return 32
circularDeque.isFull(); // return true
circularDeque.deleteLast(); // return true
circularDeque.insertFront(4); // return true
circularDeque.getFront(); // return 4

Note:

  1. All values will be in the range of [0, 1000].
  2. The number of operations will be in the range of[1, 1000].
  3. Please do not use the built-in Deque library.

解题思路

见程序注释

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MyCircularDeque

type MyCircularDeque struct {
	// contains filtered or unexported fields
}

MyCircularDeque 结构体

func Constructor

func Constructor(k int) MyCircularDeque

Constructor initialize your data structure here. Set the size of the deque to be k.

func (*MyCircularDeque) DeleteFront

func (d *MyCircularDeque) DeleteFront() bool

DeleteFront deletes an item from the front of Deque. Return true if the operation is successful.

func (*MyCircularDeque) DeleteLast

func (d *MyCircularDeque) DeleteLast() bool

DeleteLast deletes an item from the rear of Deque. Return true if the operation is successful.

func (*MyCircularDeque) GetFront

func (d *MyCircularDeque) GetFront() int

GetFront get the front item from the deque.

func (*MyCircularDeque) GetRear

func (d *MyCircularDeque) GetRear() int

GetRear get the last item from the deque.

func (*MyCircularDeque) InsertFront

func (d *MyCircularDeque) InsertFront(value int) bool

InsertFront adds an item at the front of Deque. Return true if the operation is successful.

func (*MyCircularDeque) InsertLast

func (d *MyCircularDeque) InsertLast(value int) bool

InsertLast adds an item at the rear of Deque. Return true if the operation is successful.

func (*MyCircularDeque) IsEmpty

func (d *MyCircularDeque) IsEmpty() bool

IsEmpty checks whether the circular deque is empty or not.

func (*MyCircularDeque) IsFull

func (d *MyCircularDeque) IsFull() bool

IsFull checks whether the circular deque is full or not.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL