0% found this document useful (0 votes)
26 views

Stack Operations Project

Ghfdg

Uploaded by

devjyoti7699
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Stack Operations Project

Ghfdg

Uploaded by

devjyoti7699
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Stack Operations Project

Name: [Your Name]

Reg. No.: [Your Registration Number]

Class: XII

Board: WBCHSE

Index
1. Introduction

2. Flowchart/Algorithm

3. Program Code

4. Output

5. Conclusion

1. Introduction
A stack is a linear data structure that works on the principle of Last In First Out (LIFO), meaning that

the last element inserted is the first one to be removed. This project demonstrates the following

stack operations:

- Push: Insert an element into the stack.

- Pop: Remove the top element from the stack.

- Display: View all elements in the stack.

2. Algorithms
Push Algorithm:

1. Start.

2. Check if the stack is full:

- If true, print "Stack Overflow" and exit.


- If false, proceed to the next step.

3. Increment the top pointer to the next position.

4. Insert the element at the top position.

5. End.

Pop Algorithm:

1. Start.

2. Check if the stack is empty:

- If true, print "Stack Underflow" and exit.

- If false, proceed to the next step.

3. Remove the element at the top position.

4. Decrement the top pointer.

5. End.

Display Algorithm:

1. Start.

2. Check if the stack is empty:

- If true, print "Stack is Empty" and exit.

- If false, proceed to the next step.

3. Loop through the stack from top to bottom and print each element.

4. End.

3. Program Code (C Language)


#include <stdio.h>

#define MAX 5 // Maximum size of the stack

int stack[MAX], top = -1; // Stack initialization

// Function to push an element into the stack


void push(int element) {

if (top == MAX - 1) {

printf("Stack Overflow\n");

} else {

top++;

stack[top] = element;

printf("%d pushed into stack.\n", element);

// Function to pop an element from the stack

void pop() {

if (top == -1) {

printf("Stack Underflow\n");

} else {

printf("Popped element: %d\n", stack[top]);

top--;

// Function to display the stack elements

void display() {

if (top == -1) {

printf("Stack is Empty\n");

} else {

printf("Stack elements are:\n");

for (int i = top; i >= 0; i--) {


printf("%d\n", stack[i]);

int main() {

push(10);

push(20);

push(30);

display(); // Display stack contents

pop(); // Remove top element

display(); // Display updated stack

return 0;

4. Output
Example 1: Push Operation

10 pushed into stack.

20 pushed into stack.

30 pushed into stack.

Stack elements are:

30

20

10

Example 2: Pop and Display Operation

Popped element: 30
Stack elements are:

20

10

5. Conclusion
In this project, we successfully implemented stack operations using C, covering basic functions such

as pushing, popping, and displaying elements. The program effectively handles the overflow and

underflow conditions. Stacks are highly useful in managing data for various applications such as

recursive function calls, expression evaluation, and more.

You might also like