[go: up one dir, main page]

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

QUESTION: Implementation of Stack Using Array. Code

data sturcture important program

Uploaded by

kanikashakya162
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

QUESTION: Implementation of Stack Using Array. Code

data sturcture important program

Uploaded by

kanikashakya162
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
You are on page 1/ 4

QUESTION: Implementation of stack using array.

Code:-
#include<stdio.h>
#include<stdlib.h>
#define max 10
int stack[100],i,j,top=-1;
void push();
void pop();
void show();
int peek();
int isEmpty();
int isFull();
int main()
{

push();
pop();
show();
peek();
isEmpty();
isFull();
push();

}
void push()
{

if(top==max)
{
printf("overflow:\n");
}
else{
int no;
printf("enter number of elements to be pushed:\n");
scanf("%d",&no);
while(no>0){
top=top+1;
int val;
printf("enter the value which is to be inserted:");
scanf("%d",&val);

stack[top]=val;
no=no-1;

}
}

}
void pop()
{
int j;
printf("enter number of elements to be poped:\n");
scanf("%d",&j);
if(top==-1)
{
printf("underflow:\n");
}
else
{
while(j>0)
{
printf("deleted element is %d\n",stack[top]);
top=top-1;
j=j-1;
}
}
}
void show()
{
printf("now,elements in stacks:\n");
for(int i=top;i>=0;i--)
{
printf("%d\n",stack[i]);

}
if(top==-1)
{
printf("stack is empty:\n");
}

}
int peek(){
if(top==-1)
{
return -1;
}
else
{
printf("top in the stack =%d\n",stack[top]);
}
}
int isEmpty()
{
if(top==-1)
{
printf("yes,stack is empty:");
}
}
int isFull()
{
if(top==max-1)
{
printf("stack is full\n");
}
}
Output:

You might also like