40 likes | 55 Views
A Stack in Data Structure is an abstract data type that acquires an ordered and linear sequence of elements. A stack is a First in Last out (FILO) data structure in which the item that is added first will be deleted last. In a stack, the elements are arranged in a sequence manner and thus they are called linear data structures. Stack operations in data structure like PUSH (insertion of an element) and POP (deletion of an element) are performed at the top of the stack.
E N D
What are stack operations in Data Structure? A Stack in Data Structure is an abstract data type that acquires an ordered and linear sequence of elements. A stack is a First in Last out (FILO) data structure in which the item that is added first will be deleted last. In a stack, the elements are arranged in a sequence manner and thus they are called linear data structures. Stack operations in data structure like PUSH (insertion of an element) and POP (deletion of an element) are performed at the top of the stack. Real-life examples of stacks are: Arrangement of plates: A plate can be added or removed from the top of the stack Arrangement of books in a cupboard: You can insert and remove a book only from the top of stack. Wearing and removing bangles from hand. Various types of Stack operations: The most basic operations of the stack in the data structure are the following: push() - Adds an item at the top of the stack. It is an overflow if the stack is full. pop() - Deletion of an item from the top of the stack. If the stack is empty, then it is an underflow. peek() - Topmost element in the stack is displayed.
1) push() Check if the stack is full. If the stack is full, then display "Stack overflow". If the stack is not full, increment top to the next location. Assign data to the top element. Algorithm push() If TOP >= SIZE – 1 then // Stack Overflow indicates that the Stack is FULL. TOP = TOP + 1 STACK [TOP] = ELEMENT 2) pop() Check if the stack is empty. If the stack is empty, then display "Stack Underflow". If the stack is not empty, copy top in a temporary variable. Decrement top to the previous location. Delete the temporary variable. Algorithm pop() If TOP = -1 then // Stack Underflow indicating that the Stack is EMPTY. Return STACK [TOP] TOP = TOP - 1 3) peek() Print the topmost element from the stack. Algorithm peek() Return STACK [TOP
Advantages of stacks in Data Structure: 1.Stack operations in Data Structure help to manage the data in LIFO (Last in First Out) method. It can’t be done in an array and linked list. 2.When a function called the local variables is stored in the stack, it is automatically destroyed once returned. If you want to know more about stack operations in Data Structure, visit India’s leading educational platform “Help me study Bro”. Help me study Bro is a most famous and trusted online educational platform for everyone who wants to learn about stack operations and other data structures in an easy manner. Whether you are preparing for competitive exams or want to make a career in the IT sector, data structure is a very important topic. So, visit Help me study Bro to get a deep analysis of data structure and algorithms.
Address: A-109, 3rd floor, kaushambi, Pin code – 201010 Mobile No: 9873795550 Email: adityaadityasinghraajput1996@gmail.com Website - https://www.helpmestudybro.com/