0% found this document useful (0 votes)
8 views2 pages

Stack - Array

The document presents a C program that implements a stack using an array. It includes functions for pushing, popping, checking if the stack is full or empty, and displaying the stack elements. The main function provides a menu for user interaction to perform stack operations.

Uploaded by

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

Stack - Array

The document presents a C program that implements a stack using an array. It includes functions for pushing, popping, checking if the stack is full or empty, and displaying the stack elements. The main function provides a menu for user interaction to perform stack operations.

Uploaded by

thottathylhyma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Implementation of Stack using Array

#include<stdio.h>
int top=-1;
int stk[100]; void push(int x)
int maxsize; {
if(isfull()==1)
int isfull() {
{ printf("stk is full\n");
if(top==maxsize-1) }
return(1); else
else {
return(0); top++;
} stk[top]=x;
}
int isempty() }
{
if(top==-1) void pop()
return(1); {
else if(isempty()==1)
return(0); printf("stk is empty\n");
} else
{
main() printf("element deleted is %d\n",stk[top]);
{ top--;
int ch,x; }
printf("enter size of stack\n"); }
scanf("%d",&maxsize);
while(1) void display()
{ {
printf("1,push\[Link]\[Link]\[Link]\nenter your int i;
choice\n"); printf("stack elements are\n");
scanf("%d",&ch); for(i=0;i<=top;i++)
switch(ch) printf("%d\n",stk[i]);
{ }
case 1:printf("enter new element\n");
scanf("%d",&x);
push(x);
break;
case 2:pop();
break;
case 3:display();
break;
case 4:exit(0);
default:printf("invalid choice\n");
}
}
}

You might also like