Data Structures Using C: Stacks and Queues
Data Structures Using C: Stacks and Queues
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 {(
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
11
12