A Micro Project On Dsu1111
A Micro Project On Dsu1111
A Micro Project On Dsu1111
A Stack is an abstract linear data structure operating as a group of elements that are inserted
(push operation) and withdrawn (pop operation) according to the Last in First Out (LIFO)
approach. Insertion and deletion occur on the same end (top) in a Stack. The top of the stack
is returned utilizing the peek operation.
In C, the Stack data structure is an ordered, linear series of items. It is a LIFO (Last In First
Out) data structure, which means that we can insert or withdraw an item at the top of the stack
only. It is a sequential data type, unlike an array. In an array, we can access any of its elements
utilizing indexing, but we can only access the topmost element in a stack. The name "Stack"
for this data structure comes from the metaphor of a set of physical items stacked on top of
each other. An example of this data structure would be a stack of plates: We can only add a
plate to the top of the stack and take a plate from the top of the stack. A stack of coins or a
stack of books can also be a real-life example of the stack data structure.
A MICRO PROJECT ON "Stack in C"
In C, a Stack is a linear data structure that obeys the LIFO (Last In First Out)
approach to conduct a series of basic operations like push, pop, peeks, and
traverse. A Stack can be executed utilizing an Array or Linked List.
1. Static
2. Dynamic
1. Static Stack
A Static Stack (also known as a bounded stack) has a bounded capability. It can
include a restricted number of elements. If a static stack is full and does not
have any space staying for another element to be pushed to it, it is then called
to be in an Overflow State. In C, a static stack is implemented utilizing an
Array, as arrays are static.
2. Dynamic Stack
In C, the stack data structure works utilizing the LIFO (Last In First Out)
method. Originally, we set a Peek pointer to keep track of the topmost
element of the stack. Then the stack is initialized to -1 as its peek, as we add
(push) elements to the stack, the peek gets updated to point to its topmost
element, and if we remove (pop) elements from the stack, the peek gets
reduced.
We use stack to perform its main two operations: Push and Pop, the other
operation being Peek, which is Empty, and full.
Push Operation:
We utilize the Push operation to add an element to the top of the stack.
Pop Operation:
We use the Pop operation to return and withdraw the topmost element of the
stack.
Peek Operation:
We use the Peek Operation to show the topmost element of the stack.
ISEmpty Operation:
We use the IsEmpty Operation to inspect whether the stack is empty or not.
IsFull Operation:
We can utilize the IsFull Operation to inspect whether the stack is full or not.
This operation can only be utilized with the static implementation of the stack
(using an array), also called a bounded stack
.
Time Complexity of Stack Operations
The time complexity of the several stack operations are:
The time complexity of the Pop operation would be O(1) as in this operation,
we are inserting an element at the top of the stack only.
The time complexity of the Push operation would be O(1) as in this operation,
we are withdrawing and returning an element from the top of the stack only.
The time complexity of the Peek operation would be O(1) as in this operation,
we are returning only the topmost element of the stack.
Executing Stack in C:
In C, we can execute the Stack data structure utilizing an array or a linked list.
Execution:
While performing push() and pop() operations on the stack, it takes O(1) time.
Applications of Stack
As soon as the compiler encounters a function call, it gets pushed into the stack.
In the case of nested functions, the inner functions get performed before the outer
functions. This is fully controlled by stacks.
Conclusion:
A stack is a collection of objects that are added and removed in ”last in, first out” or “LIFO”
order. That is, the first thing added is the last thing removed. For example, if you add A, B,
and then C, then the first removed will be C, then B, then A.
Stacks are ADTs or Abstract Data Types because the operations of push and pop are
universally unchanged. It does not matter what data structure you use to implement it or
what language you write it in, the specification does not change.
Reference:
https://www.google.com/
https://www.geeksforgeeks.org/
https://www.javatpoint.com