Code 3
Code 3
1
Aim :- Implement Stack ADT using Array Sarang R. Shinde
int push()
{
if (top==max-1)
prin ("stack overflow\n");
else
{
prin ("Enter the number to be added to the stack : ");
scanf("%d",&ele);
top=top+1;
stack[top]=ele;
}
}
void pop()
{
if (top==-1)
prin ("stack underflow\n");
else
{
ele= stack[top];
prin ("the deleted element is %d\n",ele);
top--;
}
}
void peek ()
{
if (top==-1)
prin ("stack underflow\n");
else
{
ele= stack[top];
prin ("the topmost element is %d\n",ele);
}
}
int display()
{
for(i=top;i>=0;i--)
prin ("%d\t",stack[i]);
prin ("\n");
}
OUTPUT :
PS C:\Users\snehal\OneDrive\Desktop> gcc 1st.c
PS C:\Users\snehal\OneDrive\Desktop> ./a.exe