queue

package
v0.0.0-...-a52c104 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue interface {
	// Enq Go 暂时还不支持泛型 只能用 interface 类型接收 入队
	Enq(e byte)

	// Deq 出队
	Deq() byte

	// IsEmpty 是否空
	IsEmpty() bool

	// IsFull 是否满
	IsFull() bool
}

Queue 先定义队列的需要实现的规范 最主要的就是出队 入队 出入队的情况下 还有 是否满 是否空

type RingQueue

type RingQueue struct {
	// 定义真正的存储结构 使用一个数组来存储  这个主要是在 函数传递的时候 函数压栈 会创建数组的副本 如果仅仅是可读没有任何问题
	// 数组和切片的区别:		切片:引用数据类型  数组:值类型
	// 我们直接使用数组 使用字节存储
	Arr [4]byte

	// 读写的位置, 操作系统就是可读 可写;
	// 代表可读的索引
	Front int
	// 代表可写的索引
	Rear int

	// 定义上一动作是出队 还是 入队
	// 优化 约定 front 在 rear 下一个位置 为 满  这种方式其实很容易 理解
	Op bool
}

RingQueue 环形队列 可固定长度 可默认长度 go的构造方法:

func NewRingQueue

func NewRingQueue() *RingQueue

NewRingQueue go 的创建构造方法

func (*RingQueue) Deq

func (q *RingQueue) Deq() byte

func (*RingQueue) Enq

func (q *RingQueue) Enq(e byte)

Enq 下面我们需要对这个结构体 实现我们规范的队列方法

func (*RingQueue) IsEmpty

func (q *RingQueue) IsEmpty() bool

func (*RingQueue) IsFull

func (q *RingQueue) IsFull() bool

Jump to

Keyboard shortcuts

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