Stacks and Queues
Stacks and Queues
Stack
Stack is a linear data structure that follows a particular order in which the
operations are performed. The order may be LIFO (last in first out) or FILO (first in
last out).
1. Push: Adds an item in the stack. If the stack is full then it is set to
be an overflow condition.
Syntax :
void push(int data)
{
if (top>=n-1)
{
printf(“Stack is Overfull! overflow”);
}
else
{
top ++;
stack[top]=data;
}
}
Pop: Removes an item from the stack the items are popped in the reverse order in which
they are Pushed if the stack is empty then it is set to be an underflow condition.
Syntax:
void pop(int data)
{
if (top<=n-1)
{
printf(“Stack is empty! underflow”);
}
else
{
printf(“The popped elements is %d”, Stack[top]);
top --;
}
}
1. Push: Adds an item in the stack. If the stack is full then it is set to be an overflow
condition.
Syntax :
void push(int data)
{
if (top>=n-1)
{
printf(“Stack is Overfull! overflow”);
}
else
{
top ++;
stack[top]=data;
}
}
2. Pop: Removes an item from the stack the items are popped in the reverse order in
which they are Pushed if the stack is empty then it is set to be an underflow
condition.
Syntax:
void pop(int data)
{
if (top<=n-1)
{
printf(“Stack is empty! underflow”);
}
else
{
printf(“The popped elements is %d”, Stack[top]);
top --;
}
}
5. Stack full: To check whether the stack is full, Returns true if the stack is full, else
false
Syntax :
void full(int stake[])
{
if (top == n-1)
{
printf (“Stack is full”);
}
else
{
printf (“stack is not full”);
}
}
Input-restricted Deque: In input-restricted, deletion can be done from both the ends
but insertion can be done only at the rear end of the queue.