Stack: Stack is a linear data structure that follows a particular order in which the operations are performed. Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow condition. Pop: Removes an item from the stack. The items are popped in the reversed order in which they are pushed. If the stack is empty, then it is said to be an Underflow condition. Peek or Top: Returns the top element of the stack. isEmpty: Returns true if the stack is empty, else false. How to understand a stack practically? There are many real-life examples of a stack. Consider the simple example of plates stacked over one another in a canteen. The plate which is at the top is the first one to be removed, i.e. the plate which has been placed at the bottommost position remains in the stack for the longest period of time. So, it can be simply seen to follow the LIFO/FILO order. Time Complexities of operations on stack: push(), pop(), isEmpty() and peek() all take O
Evaluating Postfix Expression CODE 👇 #include <stdio.h> #include <ctype.h> #define MAX 20 typedef struct { int data[MAX]; int top; }STACK; void initstack(STACK *ps) { ps->top = -1; } void push(STACK *ps, int num) { ps->top++; ps->data[ps->top]=num; } int pop(STACK *ps) { return(ps->data[ps->top--]); } int isempty(STACK *ps) { return(ps->top == -1); } int isfull(STACK *ps) { return(ps->top == MAX-1); } void main() { void Eval(char post[]); char post[20]; printf(">>Evaluating Postfix Expression<<\n"); printf("Enter The Postfix Expression:\t"); scanf("%s", post); Eval(post); } void Eval(char post[]) { int value, i, op1, op2; STACK s1; initstack(&s1); for(i=0; post[i]!='\0'; i++) { if(isalpha(post[i])) { printf("Enter The Value Of %c: \t", post[i]); scanf("%d", &value); push(&s1, value); } else { op2=po