0% found this document useful (0 votes)
15 views2 pages

Stacks

A stack is a linear data structure that operates on the Last In, First Out (LIFO) principle, allowing elements to be added and removed from the top. Key operations include push, pop, peek, isEmpty, and size, with implementations possible via arrays, linked lists, or standard libraries. Stacks have various applications such as function call management, expression evaluation, and browser history navigation.

Uploaded by

Subhadip Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Stacks

A stack is a linear data structure that operates on the Last In, First Out (LIFO) principle, allowing elements to be added and removed from the top. Key operations include push, pop, peek, isEmpty, and size, with implementations possible via arrays, linked lists, or standard libraries. Stacks have various applications such as function call management, expression evaluation, and browser history navigation.

Uploaded by

Subhadip Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Stacks – Report

1. Introduction

A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. The element
that is inserted last is the first to be removed. It is comparable to a stack of plates — you add to
the top and remove from the top.

2. Basic Operations

A stack supports the following key operations:

Operation Description

push(x) Inserts element x on top of the stack

pop() Removes and returns the top element

peek() or top() Returns the top element without removing it

isEmpty() Checks if the stack is empty

size() Returns the number of elements in the stack

3. Implementation

Stacks can be implemented using:

• Arrays (Fixed size)

• Linked Lists (Dynamic size)

• Standard Libraries (e.g., Stack in Java, list in Python)

4. Example (Stack using Array in Python)

python

CopyEdit

stack = []

# Push elements

stack.append(10)

stack.append(20)

# Pop element
stack.pop() # Output: 20

# Peek top element

top = stack[-1] # Output: 10

# Check if stack is empty

empty = len(stack) == 0

5. Applications

• Function call management (call stack in programming languages)

• Expression evaluation (postfix, prefix notation)

• Undo operations in editors

• Backtracking algorithms (e.g., maze solving)

• Browser history navigation

You might also like