Home | Projects | Notes > Data Structures & Algorithms > Stacks

Stacks

 

Introduction

A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. Elements are added (push) and removed (pop) only from the top of the stack. It can be implemented using arrays, linked lists, or other containers, and is widely used in function call management, undo operations, and parsing expressions.

 

stack-using-singly-linked-list

 

Pros:

Cons:

Compared to Queues:

 

Implementation (C++)

Header (stack.hpp)

Source (stack.cpp)

Test Driver

 

Stack Using Singly-Linked List (C)

Interface

Implementation

Test Driver