0% found this document useful (0 votes)
57 views12 pages

Data Structures Using C: Stacks and Queues

Uploaded by

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

Data Structures Using C: Stacks and Queues

Uploaded by

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

Amity School of Engineering and Technology

Data structures using C


Module 2
STACKS AND QUEUES
Prepared By
Ms. Neetu Narayan

1
Amity School of Engineering and Technology

Contents:
Applications of Stack:
Parenthesis Checker
Recursion

2
Amity School of Engineering and Technology

Contents:​
Applications of Stack
Parenthesis Checker
Recursion
Tower of Hanoi

3
Amity School of Engineering and Technology

Learning Objectives​
• Impart in-depth knowledge of data structure and its implementation
in computer programs.
• Make students understand the concepts of Stack linear data structure.
• Make students understand the applications of Stack.

4
Amity School of Engineering and Technology

Recommended Reading​
Textbooks: ​
• Yashwant Kanetkar,”Data Structure using C”, BPB Publication, 5th Edition ,2011
• A.Tannenbaum,Y. Lanhgsam and A.J. Augenstein ,” Data Structures Using C And C++ “,Prentice Hall of
India,2nd Edition,2009.
• Jean-Paul Tremblay, P.G Sorenson, “An Introduction to Data Structures with applications”, Mcgraw-
Hill ,2nd Edition ,1984.
​Reference Book: ​
• Robert L Kruse, “Data Structure and Program Design in C”, Prentice Hall (1991).
• Noel Kalicharan ,“Data Structure in C” ,Ist Edition Create space publisher, 2008.
• Mark Allen Weiss,“Data Structure and algorithm Analysis in C”,2nd Edition AddisonWesley,1996.
• E. Balagurusamy, “Problem Solving through C language”, TMH publication, Fourth Edition, 2008.
• R.S Salaria ,“Data Structures & Algorithms using C”,Khanna Publication,4th Edition,2009
• E.Horowitz and S.Sahni,”Fundamentals of Data Structures in C “,2nd Edition, Universities Press,2008.
 ​

5
Amity School of Engineering and Technology

Module Assessment​
• Quiz (Conceptual and Numerical Based)

• Assignment

6
Amity School of Engineering and Technology

Parenthesis Checker
Algorithm:
1. Whenever we see a opening parenthesis, we put it on stack.

2. For closing parenthesis, check what is at the top of the stack, if it corresponding opening parenthesis,
remove it from the top of the stack.
3. If parenthesis at the top of the stack is not corresponding opening parenthesis, return false, as there is no
point check the string further.
4. After processing entire string, check if stack is empty or not.
4.a If the stack is empty, return true.
4.b If stack is not empty, parenthesis do not match
7
Amity School of Engineering and Technology

Example:{()[(([])[])]}
Input Operation Stack Symbol
{()[([])]} PUSH {
()[([])]} PUSH {(
)[([])]} POP {
[([])]} PUSH {[
([])]} PUSH {[(
[])]} PUSH {[([
])]} POP {[(
)]} POP {[
]} POP {
} POP Empty
Accepted

8
Amity School of Engineering and Technology

Example:{()(}
Input Input Operation Stack Symbol
{()(} { PUSH {

()(} ( PUSH {(

)(} ) POP {

(} ( PUSH {(

} } POP {(

Error Not Balanced


9
Amity School of Engineering and Technology

Recursion
Recursion is the process by which function calls
itself repeatedly, until the specified condition has
been satisfied.
To solve a problem recursively, two conditions
must be satisfied:
1. A base value should be defined for which the
function should not call itself.
2. At each function call, the argument of the
function should move close to the base
value.

10
Amity School of Engineering and Technology

Factorial of a number using recursion


Algorithm: FACTO (1, 4)
FACTO ( FAC, NUMBER) FACTO (1,3)
1. If NUMBER=0, FACTO (1,2)
then FAC=1 and Return FACTO (1,1)
2. FACTO ( FAC, NUMBER-1) FACTO(1,0)
3. FAC=NUMBER*FAC FAC=1
4. Return FACTO(1,1)=1*FACTO (1,0)=1
FACTO(1,2)=2*FACTO(1,1)=2
FAC= 3*FACTO(1,2)=6
FAC=4*FACTO(1,4)=24

11
12

You might also like