Computer Science, Simply Explained.

Linear Data Structures, Part 2

⭐️️ amy ⭐️️
2 min readJan 3, 2018

Contents

The first two linear data structures we are going to discuss are Queues and Stacks. They are referred to as limited access data structures because only some elements in the structure can be accessed and therefore the operations that can be performed are limited.

Queue

A queue data structure is just like any queue or line in real life. You join the line at the end, and the first person in the line, is the first to leave. We call this method, First In, First Out or abbreviated as FIFO.

A queue data structure

The only two operations that can be performed on a queue are insertion and deletion, also known as enqueue and dequeue. We also have the ability to peek, or view, the front and back most elements of the queue.

Stack

A stack data structure is similar to a stack, or pile, in real life. The item you place in a stack first becomes the bottom of the stack as you place more items on top of it, and you can only remove from the top of the stack. Put simply, the last item to be added to the stack, is the first item that can be removed, known as Last In, First Out or abbreviated as LIFO.

A stack data structure

Insertion and deletion, or push and pop, are the only operations you can perform on a stack along with peek, which allows you to view only the top element.

The two most popular uses of stacks are to reverse a word and to undo. To reverse, you would simply push each letter as an element onto the stack, and then pop each element from the stack. To undo, just pop the most recent addition from the stack.

Reverse: the word “hello” would become “olleh” after each letter is popped from the stack

--

--