Algorithms and Data Structures - Queue

Learn how the Queue (FIFO) data structure works. Covers enqueue and dequeue operations, time complexity compared to stacks, and a Go implementation.

Read in: ja
Algorithms and Data Structures - Queue

Overview

Referencing the Algorithm Encyclopedia, we learn about algorithms and data structures.

The implementation is also available on github - bmf-san/road-to-algorithm-master.

Queue

Computational Time

Depends on the implementation form such as arrays or linked lists.

Implementation

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)]
}

References

Tags: Queue
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles