You are on page 1of 16

Department Of Information Technology

2022-2023
A MICRO-PROJECT REPORT ON

“A MICRO PROJECT ON "Stack in C.”

SUBJECT : Data Structures Using

Name Roll No Enrollment No


Pranav Deo 11 2100310169

Subject Teacher H.O.D


MISS.Swati Pakhale Mam Mr.Udaysingh Bagde
(Lecturer In Info.Tech.Department) (Info.Tech.Department)

Principal
Dr.B.G.Gawalwad Sir
Government Polytechnic Washim
GOVERNMENT POLYTECHNIC WASHIM

CERTIFICATE

This is to certify that Mr/Miss.


Roll.No

Of Semester 3rd of Diploma In Information Technology [IF3I] of Institute,


Government Polytechnic,Washim (0031) has complete their micro project
Satisfactory in course for academic
year 2022-23.
Place : Washim Seat No:

Enrollment No: Date:

Second Year Student of Information Technology has submitted a MICRO-


PROJECT report on
“Write A Report On Different Networking Devices”

Subject Teacher H.O.D


MISS.Swati Pakhale Mam Mr.Udaysingh Bagde
(Lecturer In Info.Tech.Department) (Info.Tech.Department)

Principal
Dr.B.G.Gawalwad Sir
Government Polytechnic Washim
Submitted By The Group Of

Name Roll No Enrollment No


Pranav Deo 11 2100310169

3
INDEX

TOPIC PAGE NO.

Annexure-i 05
Annexure-ii 06

Stack Data Structure 07

Data Structure 08

Stack Operation 09

Programme 10

Output 12

Conclusion / Referance 15

4
annexure-I

A MICRO PROJECT ON "Stack in C"


1.0   Aims/Benefits of the micro project

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.0   Course outcome addressed.

1) Perform basic operations on the array 


2) Apply different searching and sorting techniques 
3) Implement basic operations on the queue using array representation.

3.0 Proposed methodology

1. Focused on the selection of an appropriate topic for the micro-project.


2. Select the topic i.e. To Prepare a report on the stack in c programming.
3. Brief study on our topic.
4. Gather all information based on the topic of the micro project.
5. Analysis and study of our topic in detail.
6. Following all the above methodologies we successfully completed our microproject.

5.0 Resources used

Sr. no. Name of resource material Specifications

1 Computer System 4 GB RAM, Windows 11 OS

2 Internet Youtube

3 textbook/manual DSU 22317 Data Structures Using C

5
annexure-II
Micro-Project Report

A MICRO PROJECT ON "Stack in C"

 1.0 Brief Introduction/Rationale


In C, a Stack is a linear data structure that obeys the LIFO (Last In First Out) approach to conduct a
series of basic operations like push, pop, peeks, and traverse. A Stack can be executed utilizing an
Array or Linked List.

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

What is the Stack Data Structure in C?


In C, the Stack data structure is an ordered, linear series of items. It is a LIFO (Last In First Out) data
structure, which means that we can insert or withdraw an item at the top of the stack only. It is a
sequential data type, unlike an array. In an array, we can access any of its elements utilizing indexing,
but we can only access the topmost element in a stack.
The name "Stack" for this data
structure comes from the metaphor of a set of physical items stacked on top of each other. An example
of this data structure would be a stack of plates: We can only add a plate to the top of the stack and
take a plate from the top of the stack. A stack of coins or a stack of books can also be a real-life
example of the 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

Time Complexity of Stack Operations

The time complexity of the several stack operations are:

Push Operation: O(1)

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

Stacks can be described using structures, pointers, arrays, or linked lists.

Here, We have executed stacks using arrays in C.

9
Programme

#include

#include

#define Size 4

int Top=-1, inp_array[Size];


void Push();
void Pop();
void show();

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);

default: printf("\nInvalid choice!!");


}
}
}

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:

Operations performed by Stack

1.Push the element

2.Pop the element

3.Show

4.End

Enter the choice:1

Enter element to be inserted to the stack:10

Operations performed by Stack

1.Push the element

2.Pop the element

3.Show
12
4.End

Enter the choice:3

Elements present in the stack: 

10

Operations performed by Stack

1.Push the element

2.Pop the element

3.Show

4.End

Enter the choice:2

Popped element:  10

Operations performed by Stack

1.Push the element

2.Pop the element

3.Show

4.End

Enter the choice:3

Underflow!!

Time Complexity of Stack Operations

As noted above, only a single element can be accessed at a time in Stacks.


13
While performing push() and pop() operations on the stack, it takes O(1) time.

 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.

The Stack is utilized to solve a few of the general problems like:

1. Tower of Hanoi
2. N queens problem
3. Infix to prefix conversion, etc.

2.0  Actual Resources Use

Sr. no. Name of resource material Specifications

1 Computer System 16 GB RAM, Windows 10 OS

2 Internet Youtube / Wikipedia

3 textbook/manual DSU 22317 Data Structures Using C

3.0 Skill Developed


1. Teamwork 
2. Communication skills 
3. Able to get all information about stacks in c

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

You might also like