I am the same person and here is the overall code with some modifications: #include #include #include #include #define max 100 int top = -1; int stack[max]; char infix[max]; short postfix[max]; void push(int data); int pop(); void InToPost(); int precedence(short s); int post_evaluation(); void print(short *s); int main() { int result; printf("Enter an infix expression: "); gets(infix); InToPost(); print(postfix); result = post_evaluation(); printf("Evaluation of postfix = %d ",result); return 0; } void InToPost() { int i, j=0,x; short symbol, next; for(i=0; infix[i]!=NULL; i++) { symbol = infix[i]; switch(symbol) { case ' ': case '\t': break; case '(': push(symbol); break; case ')': while( (next = pop()) != '(') postfix[j++] = next; break; case '^': case '*': case '/': case '+': case '-': while(top!=-1 && precedence(symbol) = '0' && infix[i+1]
Problem: :( The algorithm will not work If the operand is of multiple digits. Example: Infix exp : (31+2)*2/3 Postfix exp: 312+2*3/ Array: |3| |1| |2| |+| |2| |*| |3| |/| Now when we evaluate the above expression we will push 3 1 2 And the moment we encounter an operator (+) we will pop 2 and 1. And will perform 1+2 which yeilds 3 then we will push this into the stack now the stack contains 3 3 Push 2 3 3 2 Encounter * Do 3*2 = 6 Push 6 3 6 Push 3 3 6 3 Encounter / Do 6/3 = 2 Push 2 3 2 Scanning finishes Now pop 2 So as per the algorithm the result of the above expression is 2 and that's obviously wrong. The result must be 22
Neso is SOOO underrated, I am able to solve toughest questions by learning crystal clear basics from them! You guys are amazing!
The genius behind all genius, keep the work going sir!
Sir please Continue the course rapidly , because sir we are facing problem on sorting and tree
Thank you sir one of the best channel ever ❤️🙏
Me too yrr
Mind blowing explanation sir. Thank you sir😇🙏
I have loved this video, thank you so much for making it.
You are a great teacher sir 🙏🙏🙏,,,,One humble request Sir please complete this playlist fast ,
Sir please make the video on python programming sir .I understood the C programming because of your channel.I want to learn python programming sir.
Does it work for multi digits infix expressions ? What will happen if I use a multi digit infix expression ?
Thank you for the lecture 👍🏻
Thanks ! Noted down every detail. 👍
Thank you so much Sir.
siiiiiirrrrr I can't thank you enoughhhhh
Do make videos on prefix also
For entering more than one digit number i made some modifications as:
void InToPost()
{
int i, j=0,x;
char symbol, next;
for(i=0; i
I am the same person and here is the overall code with some modifications:
#include
#include
#include
#include
#define max 100
int top = -1;
int stack[max];
char infix[max];
short postfix[max];
void push(int data);
int pop();
void InToPost();
int precedence(short s);
int post_evaluation();
void print(short *s);
int main()
{
int result;
printf("Enter an infix expression: ");
gets(infix);
InToPost();
print(postfix);
result = post_evaluation();
printf("Evaluation of postfix = %d
",result);
return 0;
}
void InToPost()
{
int i, j=0,x;
short symbol, next;
for(i=0; infix[i]!=NULL; i++)
{
symbol = infix[i];
switch(symbol)
{
case ' ':
case '\t':
break;
case '(':
push(symbol);
break;
case ')':
while( (next = pop()) != '(')
postfix[j++] = next;
break;
case '^':
case '*':
case '/':
case '+':
case '-':
while(top!=-1 && precedence(symbol) = '0' && infix[i+1]
Sir please upload all dsa lecturex before 10 january as I have final semester exams from 15 january.
Cool sir. i hope can converted to arduino code.
Sir also add queue topic
Please Sir upload lectures early
Problem: :(
The algorithm will not work If the operand is of multiple digits.
Example:
Infix exp : (31+2)*2/3
Postfix exp: 312+2*3/
Array: |3| |1| |2| |+| |2| |*| |3| |/|
Now when we evaluate the above expression we will push 3 1 2
And the moment we encounter an operator (+) we will pop 2 and 1. And will perform 1+2 which yeilds 3 then we will push this into the stack now the stack contains
3 3
Push 2
3 3 2
Encounter *
Do 3*2 = 6
Push 6
3 6
Push 3
3 6 3
Encounter /
Do 6/3 = 2
Push 2
3 2
Scanning finishes
Now pop 2
So as per the algorithm the result of the above expression is 2 and that's obviously wrong.
The result must be 22
Yes sir!!
Yes obviously it will not work with multiple digits, that's why it is called as infix (a operator between 2 operands : A+B.
Sir has already mentioned in the video that is the drawback we can only perform on single digit operands
it is single digit evaluation bro😊
so you can take single digit
Sir tell the computer organisation course sir,please
th-cam.com/play/PLBlnK6fEyqRgLLlzdgiTUKULKJPYc0A4q.html
1st view 🤭
Ha ha 👍