










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











A stack is a linear data structure. It is controlled by two operations : push and pop. Both the operations take place from one end of the stack, usually called top. Top points to the current top positions of the stack. Push operation adds an element to the top of the stack. Pop operation removes an element from the top of the stack. These two operations implements the LIFO method.
Stack can be implemented in two ways :
(^) Initially when the stack is empty, TOP can have any integer value other than any valid index number of the array. Let TOP = -1; (^) The first element in the empty stack goes to the 0th position of the array and the Top is initialized to value 0. (^) After this every push operation increase the TOP by 1 and inserts new data at that particular position. (^) As arrays are fixed in length, elements can not be inserted beyond the maximum size of the array. Pushing data beyond the maximum size of the stack results in “data overflow”.
PROGRAM TO ILLUSTRATE OPERATIONS ON STACK AS AN INTEGER ARRAY case 3: { display(); break; } c } case 4: { cout<<"Exit"<<endl; break; } default: { cout<<"Invalid Choice"<<endl; } }
STACK AS A LINKED LISTSTACK AS A LINKED LIST Linked list implementation of stack uses A linked list to store data A pointer TOP pointing to the top most position of the stack. NOTE: Each node of a stack as a linked list has two parts : data part and link part and is created with the help of self referential structure. The data part stores the data and link part stores the address of the next node of the linked list.
PROGRAM TO ILLUSTRATE OPERATIONS ON STACK AS A LINKED LIST : Explanation