アルゴリズムとデータ構造 - キュー

アルゴリズムとデータ構造 - キュー

Read in: en
アルゴリズムとデータ構造 - キュー

概要

アルゴリズム図鑑を参考に、アルゴリズムとデータ構造を学ぶ。

実装はgithub - bmf-san/road-to-algorithm-masterにも置いてある。

キュー

計算時間

配列や連結リストなど実装形式による。

実装

package main

// Queue is a queue.
type Queue struct {
	nodes []*Node
}

// Node is a item of a stack.
type Node struct {
	value string
}

// newQueue create a Stack.
func newQueue() *Queue {
	return &Queue{}
}

// enqueue adds an node to the end of the queue.
func (s *Queue) enqueue(n *Node) {
	s.nodes = append(s.nodes, n)
}

// dequeue removes an node from the top of the queue.
func (s *Queue) dequeue() {
	s.nodes = s.nodes[1:len(s.nodes)]
}

参考

Tags: キュー
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ サポート

このブログを応援していただける方は、以下からサポートをお願いします。いただいたサポートはブログ運営・技術研鑽に活用します。


関連記事