CS-212L
Data Structures and Algorithm CS Lab Manual
Academic Year: 2020
Semester 3
Course Code: CS-212L
Course Title: Data Structures and Algorithm Lab
CS-212L
Data Structures and Algorithm CS Lab Manual
Type of Lab: Open Ended Weightage: 10%
CLO 1: CLO’s.
State the Rubric Cognitive/Understanding CLO1 Rubric
A
Rubric A: Cognitive Domain
Evaluation Method: GA shall evaluate the students for Question
according to the following rubrics.
CLO 0 1 2 3 4
CLO1
Page 1 of 4
CS-212L
Data Structures and Algorithm CS Lab Manual
Lab #
Objectives: Learn the concepts of Stack Data Structure
Processing Steps:
Step1: Ordering!
We many times in our life has saw an ordering in doing some task. Mean to say,
you might has observed that when we do place notebooks on each other, first
notebook is always at the end of pile, and when we try to get the first book, we have
to first remove the book that are present on the top of that, and first inserted book
was taken out at the last.
This phenomenon, we also used in Computer science, we have some problems
which can be solve easily with this mechanism, to implement it we have a Data
Structure known as Stack.
Step 2: What is Stack?
Stack is a linear data structure, which push and pop the elements in some specific
ordering mechanism.
LIFO
LIFO (Last In First Out) or FILO (First In Last Out) is a ordering mechanism used
by the stack data structure.
Step 3: Why Stack?
Stack data Structure is a general data structure which might and being used in many
algorithms. Like you can find Stack in
• Undo/Redo
• Postfix expression to Infix conversation
• Parameter passing
Stack is dynamic, and every program has by default some memory area reserved for
stack, and as element is inserted stack size decreases.
Page 2 of 4
CS-212L
Data Structures and Algorithm CS Lab Manual
Step 4: How Stack Implemented?
Stack uses the “Stack top pointer” variable to handle the LIFO mechanism
It has three funtions
• Push(data)
• Pop()
• Top()
Push(data):
This function insert value at the “Stack top” pointer variable index and increment the
pointer
Step1: Stack [Stack_top] = data
Step2: Stack_top = Stack_top + 1;
Pop():
This function returns the value at the “Stack top” pointer variable index and
decrement the pointer
Step1: return Stack [Stack_top]
Step2: Stack_top = Stack_top - 1;
Page 3 of 4
CS-212L
Data Structures and Algorithm CS Lab Manual
Top():
This function returns the value at the “Stack top” pointer variable index
Step1: return Stack [Stack_top]
Lab Task:
• Implement the Stack Data Structure with standard functions of Stack
Assignment:
• You are given a set of strings which contain only a’s and b’s, your program
should be able to check whether the string have same number of a’s and b’s
in it or not
o Your program will say respond positive if it get “ab, aabb, aaabbbb,
bbbaaa) and say false when it get (‘aab, bbba, aaabbbb” )
o Solve this problem using Stack
o Code should be commented properly, execute and terminate
normally. Plagiarism will cause zero marking.
Page 4 of 4