0% found this document useful (0 votes)
18 views8 pages

Implementaion of Stack 2

Uploaded by

oldxmonk49
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)
18 views8 pages

Implementaion of Stack 2

Uploaded by

oldxmonk49
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/ 8

Name=Akshay Rajendra Sonwane

Program 2= Implementation of stack


Roll No= 65 Batch=S4

#include <stdio.h>

#include <conio.h>

#include <process.h>

#include <stdlib.h>

#define MAX_SIZE 10

#define bottom -1

voidinitStack( );

intisFull();

intisEmpty();

void push(int);

void pop();

void peep();

void traverse();

int stack[MAX_SIZE];

int top;

void main()

int choice, item;


do

printf("\n....MENU... \n");

printf("1. Initialize stack\n");

printf("2. Push\n");

printf("3. Pop\n");

printf("4. Peep\n");

printf("5. Traverse\n");

printf("6. Quit\n");

printf("Enter your choice\n");

scanf("%d", &choice);

if (choice <1 || choice > 6)

printf("Invalid choice...try again\n");

continue;

switch (choice)

case 1:

initStack();

break;
case 2:

printf("Enter the item to Push\n");

scanf("%d", &item);

push(item);

break;

case 3:

pop();

break;

case 4:

peep();

break;

case 5:

traverse();

break;

case 6:

printf("End of program\n");

exit(0);

while (choice != 6);

voidinitStack()
{

top = bottom;

printf("Stack initialized\n");

intisFull()

if(top == MAX_SIZE - 1)

return (1);

else

return (0);

intisEmpty()

if (top == bottom)

return (1);

else

return (0);

void push(intnewitem)

if (isFull())
printf("Stack overflow\n");

else

top =top+1;

stack[top] = newitem;

void pop()

if (isEmpty())

printf("Stack underflow\n");

else

printf("Item Popped = %d\n", stack[top]);

top = top-1;

void peep()

if (isEmpty())

printf("Stack is empty\n");

else
printf("Top of stack= %d\n", stack[top]);

void traverse()

int i;

if(isEmpty())

printf("Stack is empty\n");

else

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

for (i = top; i > bottom; i--)

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

} getch();

}
Output=
1. STACK INITILIZED

2. STACK PUSH OPERATION

3. STACK POP OPERATION


4. STACK TRAVERSAL OPERATION

5. STACK PEEP OPERATION

You might also like