Application of Stacks (Infix to Postfix) - Part 8

preview_player
Показать описание
Data Structures: Application of Stacks (Infix to Postfix) - Part 8
Topics discussed:
1) Writing a C program to evaluate the postfix expression.

Music:
Axol x Alex Skrindo - You [NCS Release]

#DataStructuresByNeso #DataStructures #Stacks #ApplicationOfStacks
Рекомендации по теме
Комментарии
Автор

Neso is SOOO underrated, I am able to solve toughest questions by learning crystal clear basics from them! You guys are amazing!

nisharathod
Автор

The genius behind all genius, keep the work going sir!

AzreenRajieveMANANGGOLO
Автор

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 ❤️🙏

subhajitchoudhury
Автор

Mind blowing explanation sir. Thank you sir😇🙏

bisalranjanswain
Автор

I have loved this video, thank you so much for making it.

shivajichate
Автор

You are a great teacher sir 🙏🙏🙏, , , , One humble request Sir please complete this playlist fast,

ankitxalxotoo
Автор

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.

-anuhyajanjam
Автор

Does it work for multi digits infix expressions ? What will happen if I use a multi digit infix expression ?

MDSagor-tuxw
Автор

Sir please upload all dsa lecturex before 10 january as I have final semester exams from 15 january.

lokendrasinghrao
Автор

Cool sir. i hope can converted to arduino code.

galihtanu
Автор

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<strlen(infix); 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) <= precedence(stack[top]))
postfix[j++] = pop();
push(symbol);
break;
default:
while(infix[i+1] >= '0' && infix[i+1] <= '9')
{
x = ((symbol-'0') * 10) + (infix[++i]-'0');
symbol = (x+'0');
}
postfix[j++] = symbol;
break;
}
}
while(top != -1)
postfix[j++] = pop();
postfix[j++] = '\0';
}

int precedence(char s)
{
switch(s)
{
case '^': return 3;
break;
case '*':
case '/': return 2;
break;
case '+':
case '-': return 1;
break;
default: return 0;
break;
}
}

int post_evaluation()
{
int i, a, b, n;
for(i=0; i<strlen(postfix); i++)
{
if(postfix[i]!='+' && postfix[i]!='-' && postfix[i]!='*'
&& postfix[i]!='/' && postfix[i]!='^')
push(postfix[i]-'0');
else
{
a = pop();
b = pop();
switch(postfix[i])
{
case '+': push(b+a);
break;
case '-': push(b-a);
break;
case '*': push(b*a);
break;
case '/': push(b/a);
break;
case '^': push(pow(b, a));
break;
}
}
}
return pop();
}

void print(char *s)
{
int i=0;
printf("Postfix expression: ");
while(s[i])
{
if(postfix[i]!='+' && postfix[i]!='-' && postfix[i]!='*'
&& postfix[i]!='/' && postfix[i]!='^')
printf("(%d)", (s[i]-'0'));
else
printf("%c", s[i]);
i++;
}
printf("\n");
}

I hope i done well.❤

mohamedsamir
Автор

Sir tell the computer organisation course sir, please

kycideas
Автор

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

anonyanonymous