0% found this document useful (0 votes)
5 views4 pages

Array-Based Stack Implementation in C

Uploaded by

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

Array-Based Stack Implementation in C

Uploaded by

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

Aim: Array Implementation of Stack.

#include<stdio.h>
int size=5;
int top=-1;
int val;
int choice;
int STK[5];
int i;
int j;
int k;
int isstkfull()
{
if(top==(size-1))
return 1;
else
return 0;
}
int isstkempty()
{
if(top==-1)
return 1;
else
return 0;
}

void push(int val)


{
if(isstkfull())
printf("Stack is isstkfull\n");
else
{
top++;
STK[top]=val;
}
}
int pop()
{
if(isstkempty())
printf("Stack is isstkempty\n");
else
{
val=STK[top];
top--;
return val;
}
}
int stktop()
{
if(isstkempty())
printf("Stack is isstkempty\n");
else
{
val=STK[top];
return val;
}
}
void display()
{
if(isstkempty())
printf("Stack is isstkempty\n");
else
{
for(i=top;i>=0;i--)
{
val=STK[i];
printf("%d\n",val);
}
}
}
int main()
{
do
{
printf("[Link]\[Link]\[Link]\[Link] Stack isstkfull\[Link] Stack isstkempty\[Link]\
n7. Exit\n");
printf("Enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the value to be pushed into the Stack\n");
scanf("%d",&val);
push(val);
break;
case 2:
val = pop();
printf("Pop val is = %d\n",val);
break;
case 3:
val = stktop();
printf("TOp of stack val is = %d\n",val);
break;
case 4:
j=isstkfull();
if(j==1)
printf("Stack is isstkfull\n");
else
printf("Stack is not isstkfull\n");
break;
case 5:
k=isstkempty();
if(k==1)
printf("Stack is not isstkempty\n");
else
printf("Stack is not isstkempty\n");
break;
case 6:
display();
break;
case 7: printf("Thank you for using my program\n");
break;

}
}while(choice!=7);
}

You might also like