What is stack implementation in data structure
Part 2
stack
stack is a linear data structure which is used to store data in LIFO(last in first out) or FILO(first in last out)
What is a Data Structure?
Read Part 1
A data structure is a logical way of organizing data that makes them efficient to use.
Operations on Data Structures
The basic operations that are performed on data structures are as follows:
1. Insertion. Insertion means addition of a new data element in a data structure.
2. Deletion. Deletion means removal of a data element from a data structure. The data element is searched for before its removal.
3. Searching. Searching involves searching for the specified data element in a data structure
4. Traversal. Traversal of a data structure means processing all the data elements of it, one by one.
5. Sorting. Arranging data elements of a data structure in a specified order is called sorting. 6. Merging. Combining elements of two similar data structures to form a new data structure of same type, is called merging.
Peek
Refers to inspecting the value at the stack's top without removing it. It is also sometimes referred as inspection.
Overflow
Refers to situation (ERROR) when one tries to push an item in stack that is full. This situation occurs when the size of the stack is fixed and cannot grow further or there is no memory left to accommodate new item.
Underflow
Refers to situation (ERROR) when one tries to pop/delete an item from an empty stack. That is, stack is currently having no item and still one tries to pop an item.
Concept of
Concept of Stack:
(1) PUSH- Insertion of Data in the Stack
(2) POP- Deletion of Data from from Stack
(3) PEEK- View Top element /Last inserted element
(4) DISPLAY-To show all data from stack
Note:-
For representation of stack we used to LIST
(1) POP => If the value not found during deleting
value from the stack then it returns Stack Underflow
(4) PUSH 40=> Append 40 value in 2 Index of stack
(5) PUSH 50=> Append 50 value in 3 Index of stack
(6) POP 50=> Delete 50 value from the 3 Index of stack
(7) POP 40=> Delete 40 value from the 2 Index of stack
(10) Display =>It displays All Element of stack in opposite Order
No comments:
Post a Comment
for more information please share like comment and subscribe