Search⌘ K
AI Features

Queue Implementation Using Doubly Linked List

Explore the implementation of a double-ended queue or deque using a doubly linked list in Go. Learn how to add and remove elements from both front and back, how to peek without removal, and how to print queue elements. This lesson helps you understand core queue operations and data structure manipulation in Go for effective problem-solving.

A double-ended queue or a deque (sometimes pronounced “deck”) is an abstract data type in which elements can be added to or removed from both ends. Let’s look at the linked list implementation of the deque.

Queue struct

First of all, let’s define a struct for our deque using a doubly linked list.

Go (1.6.2)
type Node struct {
value int
next *Node
prev *Node
}
type Deque struct {
head *Node
tail *Node
size int
}

Queue operations

Now, let’s make some common queue operations by using the ...