Problem0232

package
v0.0.0-...-4e682c9 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2018 License: MIT Imports: 0 Imported by: 0

README

232. Implement Queue using Stacks

题目

Implement the following operations of a queue using stacks.

push(x) -- Push element x to the back of queue.

pop() -- Removes the element from in front of queue.

peek() -- Get the front element.

empty() -- Return whether the queue is empty.

Notes:

You must use only standard operations of a stack -- which means only push to top, peek/pop from top, size, and is empty operations are valid. Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack. You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).

解题思路

见程序注释

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MyQueue

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

MyQueue 是利用 栈 实现的队列

func Constructor

func Constructor() MyQueue

Constructor Initialize your data structure here.

func (*MyQueue) Empty

func (mq *MyQueue) Empty() bool

Empty returns whether the queue is empty.

func (*MyQueue) Peek

func (mq *MyQueue) Peek() int

Peek Get the front element.

func (*MyQueue) Pop

func (mq *MyQueue) Pop() int

Pop Removes the element from in front of queue and returns that element.

func (*MyQueue) Push

func (mq *MyQueue) Push(x int)

Push element x to the back of queue.

type Stack

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

Stack 是用于存放 int 的 栈

func NewStack

func NewStack() *Stack

NewStack 返回 *kit.Stack

func (*Stack) IsEmpty

func (s *Stack) IsEmpty() bool

IsEmpty 反馈 s 是否为空

func (*Stack) Len

func (s *Stack) Len() int

Len 返回 s 的长度

func (*Stack) Pop

func (s *Stack) Pop() int

Pop 从 s 中取出最后放入 栈 的值

func (*Stack) Push

func (s *Stack) Push(n int)

Push 把 n 放入 栈

Jump to

Keyboard shortcuts

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