1.2.b. Stack ADT
1.2.b. Stack ADT
DA
DATYPETTAASTRUCTURESSTRUTHE SUBJECT(CommonNAME toHERECSE & IT)
UNIT NO 1
LINEAR DATA STRUCTURES - STACKS, QUEUES
CS8391
DATA STRUCTURES (Common to CSE & IT)
20ITPC301
STACK
20ITPC301
DATA STRUCTURES (Common to CSE & IT)
STACK
20ITPC301
DATA STRUCTURES (Common to CSE & IT)
What is a STACK ?
A stack is linear data structures, a container of elements that are inserted and removed according to the
last-in first-out (LIFO) principle.
Examples
In a stack all operation like insertion and deletion are performed at only one end called Top
• Instead of using array, we can also use linked list to implement stack.
• Linked list allocates the memory dynamically.
• However, time complexity in both the scenario is same for all the operations i.e. push, pop and peek.
• In linked list implementation of stack, the nodes are maintained non-contiguously in the memory.
• Each node contains a pointer to its immediate successor node in the stack.
• Stack is said to be overflown if the space left in the memory heap is not enough to create a node.
20ITPC301
DATA STRUCTURES (Common to CSE & IT)
int isempty()
{
return top==NULL;
}
20ITPC301
void display()
{
if(top == NULL)
printf("\nStack is
Empty!!!\n"); else{
struct Node *temp = top;
while(temp->next != NULL){
printf("%d--->",temp->data);