0% found this document useful (0 votes)
2 views5 pages

Final Project

This document is a project workbook for a menu-based C program that implements stack operations using data structures. It includes acknowledgments, coding for push, pop, and display functions, and an algorithm outlining the operations of the stack. The stack is limited to 5 elements and provides error messages for overflow and underflow conditions.

Uploaded by

rajdeepm.dev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Final Project

This document is a project workbook for a menu-based C program that implements stack operations using data structures. It includes acknowledgments, coding for push, pop, and display functions, and an algorithm outlining the operations of the stack. The stack is limited to 5 elements and provides error messages for overflow and underflow conditions.

Uploaded by

rajdeepm.dev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

উচ্চ মাধ্যমমক মিক্ষা সংসদ

Computer Science
Project Workbook

XI

Subject: Menu base Project based on C language based Data structure on


Stack showing use of push(), pop() & Display()

Name : ____________________________

Registration no: __________________________________________

School : ________________________________

1
Acknowledgment

I would like to express my heartfelt gratitude to my school, Raiganj Coronation


High School, for providing me with the opportunity to work on this project titled
"Menu-Based C Program for Stack Operations (Push, Pop & Display)".

I extend my sincere thanks to my teachers for their invaluable guidance and


encouragement throughout the completion of this project. Their support has helped
me gain a deeper understanding of data structures, particularly the stack operations
implemented in C.

I would also like to acknowledge my family and friends for their continuous
motivation and support during this project. Their encouragement played a
significant role in successfully completing this work.

Lastly, I am grateful for the resources and learning materials that assisted me in
developing this menu-driven stack program, enhancing my programming skills.

Submitted by:
Soumydeep Saha
Class: XI(Science)

Raiganj Coronation High School

2
Coding
#include<stdio.h> void main()
#include<conio.h> {
int ar[5],i,top=-1,num; int ch;
void push() clrscr();
{ while(1)
clrscr(); {
if(top==4) clrscr();
printf("Stack overflow!\n"); printf("Menu\n");
else
{ printf("1.Display\n2.Push\n3.Pop\n4.Exit\nSelect=");
++top; scanf("%d", &ch);
printf("Enter a number="); if(ch==1) display();
scanf("%d", &num); if(ch==2) push();
ar[top]=num; if(ch==3) pop();
} if(ch==4) break;
} }
void pop() getch();
{ }
clrscr();
if(top==-1)
printf("\nStack underflow!\n");
else
{ printf("\n%d is popped\n", ar[top]);
getch();
top=top-1;
}
}
void display()
{
clrscr();
printf("\nStack elements\n");
for(i=top;i>=0;i--)
{
printf("%d\n", ar[i]);
}
getch();
}

3
This C program implements a stack using an array. The stack follows the LIFO (Last In, First
Out) principle. The program provides options to:

 Push an element onto the stack


 Pop an element from the stack
 Display the current elements in the stack

The stack has a fixed size of 5 elements. If the stack is full, it shows "Stack overflow", and if
it's empty, it shows "Stack underflow".

Algorithm

1. Push Operation

Step 1: Check if top == 4 (stack full). If true, print "Stack Overflow" and return.
Step 2: If not full, increment top by 1.
Step 3: Read the new element from the user.
Step 4: Store the element at ar[top].

2. Pop Operation

Step 1: Check if top == -1 (stack empty). If true, print "Stack Underflow" and return.
Step 2: Display the element at ar[top] as the popped value.
Step 3: Decrease top by 1.

3. Display Operation

Step 1: Check if top == -1 (stack empty). If true, print "Stack is empty" and return.
Step 2: Print all elements from top to 0.

4. Main Program Flow

Step 1: Start an infinite loop for menu selection.


Step 2: Show options: Display, Push, Pop, Exit.
Step 3: Read user's choice.
Step 4: Call the corresponding function (push(), pop(), display()).
Step 5: If choice is 4, exit the loop.

4
5

You might also like