Stack Data Structure: LIFO Principle, Implementation, and Applications, Schemes and Mind Maps of Computer science

A comprehensive overview of the stack data structure, covering its lifo principle, implementation using arrays and linked lists, and key operations such as push, pop, and peek. It includes detailed explanations of stack overflow and underflow conditions, along with practical examples and c code implementations for single and multiple stacks. The document also explores the conversion of arithmetic expressions using infix, prefix, and postfix notations, and presents algorithms for evaluating prefix and postfix expressions. Additionally, it covers the application of stacks in parentheses checking, making it a valuable resource for understanding and implementing stacks in computer science. Useful for high school and university students.

Typology: Schemes and Mind Maps

2024/2025

Uploaded on 07/09/2025

sam-mu
sam-mu 🇮🇳

2 documents

1 / 92

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Stacks
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c

Partial preview of the text

Download Stack Data Structure: LIFO Principle, Implementation, and Applications and more Schemes and Mind Maps Computer science in PDF only on Docsity!

Stacks

Stack is a linear data structure which stores its elements in an ordered

manner

where do we need stacks in computer

science?

Ans: function calls

Example:

Executing function A. In the course of its execution, function A calls another

function B. Function B in turn calls another function C, which calls function D.

Whenever a function calls another function, the calling function is pushed onto

the top of the stack. This is because after the called function gets executed, the

control is passed back to the calling function

Now when function E is executed, function D will be removed from the top of the

stack and executed. Once function D gets completely executed, function C will be

removed from the stack for execution. The whole procedure will be repeated until all

the functions get executed.

Stacks can be implemented using either arrays or linked lists

  • In the computer’s memory, stacks can be represented as a linear array.

Every stack has a variable called TOP associated with it, which is used to store the address of

the topmost element of the stack.

  • It is this position where the element will be added to or deleted from. There is another variable called

MAX, which is used to store the maximum number of elements that the stack can hold.

Stack_arr[]

In an array insertion and deletion can be done in any place

Stack_arr[] is an array implementation of stack so it can perform insertion/deletion at the end only

Before inserting the value, first check if TOP=MAX–1 , because if

that is the case, then the stack is full and no more insertions can be

done.

If an attempt is made to insert a value in a stack that is already

full, an OVERFLOW message is printed

The push operation is used to insert an element into the stack.

The new element is added at the topmost position of the stack.

For push operation top has to be incremented by 1

Then value can be inserted on that top.

Peek Operation

Peek is an operation that returns the value of the topmost

element of the stack without deleting it from the stack

Peek operation first checks if the stack is empty, i.e., if TOP = NULL,

then an appropriate message is printed, else the value is returned

Write a program to perform Push, Pop

and operations on a stack