Professional Documents
Culture Documents
2022-2023
A MICRO-PROJECT REPORT ON
Principal
Dr.B.G.Gawalwad Sir
Government Polytechnic Washim
GOVERNMENT POLYTECHNIC WASHIM
CERTIFICATE
Principal
Dr.B.G.Gawalwad Sir
Government Polytechnic Washim
Submitted By The Group Of
3
INDEX
Annexure-i 05
Annexure-ii 06
Data Structure 08
Stack Operation 09
Programme 10
Output 12
Conclusion / Referance 15
4
annexure-I
Data structure is an important aspect for Computer Engineering and Information Technology Diploma
graduates. The data structure is a logical & mathematical model of storing & organizing data in a
particular way in a computer. The methods and techniques of Data Structures are widely used in
industries. After learning this subject students will be able to identify the problem, analyze different
algorithms to solve the problem & choose the most appropriate data structure to represent the data.
2 Internet Youtube
5
annexure-II
Micro-Project Report
A Stack is an abstract linear data structure operating as a group of elements that are inserted (push
operation) and withdrawn (pop operation) according to the Last in First Out (LIFO) approach. Insertion
and deletion occur on the same end (top) in a Stack. The top of the stack is returned utilizing the peek
operation.
6
Stack Data Structure
7
Data Structures
There are two kinds of Stack data structures: Static and Dynamic
1. Static Stack
A Static Stack (also known as a bounded stack) has a bounded capability. It can include a restricted
number of elements. If a static stack is full and does not have any space staying for another element
to be pushed to it, it is then called to be in an Overflow State. In C, a static stack is implemented
utilizing an Array, as arrays are static.
2. Dynamic Stack
A Dynamic Stack is a stack data structure whose capability (maximum elements that can be held)
rises or decreases in runtime, based on the operations (push or pop) performed on it. In C, a
dynamic stack is implemented using a Linked List, as linked lists are dynamic data structures.
How does Stack Work in C?
In C, the stack data structure works utilizing the LIFO (Last In First Out) method. Originally, we
set a Peek pointer to keep track of the topmost element of the stack. Then the stack is
initialized to -1 as its peek, as we add (push) elements to the stack, the peek gets updated to
point to its topmost element, and if we remove (pop) elements from the stack, the peek gets
reduced.
We use stack to perform its main two operations: Push and Pop, the other operation being
Peek, which is Empty, and full.
Push Operation
We utilize the Push operation to add an element to the top of the stack.
Pop Operation
We use the Pop operation to return and withdraw the topmost element of the stack.
Peek Operation
We use the Peek Operation to show the topmost element of the stack.
IsEmpty Operation
We use the IsEmpty Operation to inspect whether the stack is empty or not.
IsFull Operation
This operation can only be utilized with the static implementation of the stack (using an array), also
called a bounded stack
.
8
Stack Operations
The time complexity of the Pop operation would be O(1) as in this operation, we are inserting an
element at the top of the stack only.
Pop Operation: O(1)
The time complexity of the Push operation would be O(1) as in this operation, we are withdrawing and
returning an element from the top of the stack only.
Peek Operation: O(1)
The time complexity of the Peek operation would be O(1) as in this operation, we are returning only the
topmost element of the stack.
IsEmpty Operation: O(1)
The time complexity of the IsEmpty operation would be O(1) as in this operation, we are reviewing
whether the topmost element is null or not.
IsFull Operation: O(1)
The time complexity of the IsFull operation would be O(1) as in this operation, we are inspecting
whether the topmost element is at the maximum position or not.
Executing Stack in C
In C, we can execute the Stack data structure utilizing an array or a linked list.
Stack Program in C utilizing Array
We will be utilizing an array to implement a Static Stack (Bounded Stack) as arrays are static in C.
A Static Stack has a bounded capacity. A static stack is called to be in an Overflow State if it is full (no
elements can be further pushed into it).
Execution
9
Programme
#include
#include
#define Size 4
int main()
{
int choice;
while(1)
{
printf("\nOperations performed by Stack");
printf("\n1.Push the element\n2.Pop the element\n3.Show\
n4.End");
printf("\n\nEnter the choice:");
scanf("%d",&choice);
switch(choice)
{
case 1: Push();
break;
case 2: Pop();
break;
case 3: show();
10
break;
case 4: exit(0);
void Push()
{
int x;
if(Top==Size-1)
{
printf("\nOverflow!!");
}
else
{
printf("\nEnter element to be inserted to the stack:");
scanf("%d",&x);
Top=Top+1;
inp_array[Top]=x;
}
}
void Pop()
{
if(Top==-1)
{
printf("\nUnderflow!!");
}
else
{
printf("\nPopped element: %d",inp_array[Top]);
Top=Top-1;
}
}
11
void show()
{
if(Top==-1)
{
printf("\nUnderflow!!");
}
else
{
printf("\nElements present in the stack: \n");
for(int i=Top;i>=0;--i)
printf("%d\n",inp_array[i]);
}
}
Output:
3.Show
4.End
3.Show
12
4.End
10
3.Show
4.End
Popped element: 10
3.Show
4.End
Underflow!!
Applications of Stack
As soon as the compiler encounters a function call, it gets pushed into the stack.
In the case of nested functions, the inner functions get performed before the outer functions. This is
fully controlled by stacks.
1. Tower of Hanoi
2. N queens problem
3. Infix to prefix conversion, etc.
14
Conclusion
we have comprehended the concept of Stack data structure and its implementation utilizing
Arrays in C.
Referance
Google Chrome
Wikipedia
Other Webs
15
THANK YOU
16