Skip to main content

Posts

Showing posts with the label data-structure

Implementing Monotonic Stack in Python

A monotonic stack is an extension of the Stack data structure in which the elements of the stack are in either increasing or decreasing order. The stack in which the items are in increasing order is called the monotonically increasing stack, the top element of such a stack will be the largest of all the elements below. On the other hand, if the items are arranged in a decreasing order then the stack is called a monotonically decreasing stack, on which the top element will be the smallest of all the elements below. Monotonic stacks are very popular in competitive programming.

Double ended queue (deque) in C

A double-ended queue, pronounced deque in short is a LIFO queue where entries can be pushed and popped at both the ends of the queue, apart from push and pop an additional peek method is also discussed which fetches the value at either ends without removing it. In this article, one such queue is implemented using the C language.