Application of Stacks (Infix to Postfix) - Part 7

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

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

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

No one can dry run and traverse like him. 💖

rajeshprajapati
Автор

Great Video!
You made it so clear that I didnt even need to watch any other video related to this topic
Now this is what I call the best teaching

nightfury
Автор

My DSA paid course feels like get wasted after watching this video😂😂. Now I will watch your DSA full playlist. BTW your video's information is very depth. Thankyou❤❤❤❤

istiyak
Автор

This video of infix to postfix conversion helped me a lot😅 I am very thankful to u sir for explaining so well.. ❤

ishwaryaishwarya
Автор

Never before! And never after! This type of

polireddybheemarjun
Автор

After watching this lecture, I felt its too easy.
Thank you.

DeneshwaraSaiIla
Автор

Thanks for teaching us ❤️❤️.you complete this code in 137 line and after clearing this concept with your video i complete this code in 97 line. ❤️❤️

smitkhalasi
Автор

Sir You are amazing. I can't thank you enough.👏👏👏👏👏

rafiashan
Автор

Perfectly explained ❤️❤️seriously he is best

amazinggamer
Автор

Sir plz upload lecture on program for evaluation of postfix expression.

saniyamansuri
Автор

works for single digit input, turned a simple code into unnecessarily big yet there is a big flaw.

second
Автор

thank you so much for this great explanation

sergion_brayen
Автор

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100

char stack[MAX];
char infix[MAX], postfix[MAX];
int top = -1;

void push(char);
char pop();
int isEmpty();
void inToPost();
void print();
int precedence(char);

int main()
{
printf("Enter the infix expression: ");
gets(infix);
inToPost();
print();
return 0;
}

void inToPost()
{
int i, j = 0;
char symbol, next;
for (i = 0; i < strlen(infix); i++)
{
symbol = infix[i];
switch (symbol)
{
case '(':
push(symbol);
break;
case ')':
while ((next = pop()) != '(')
postfix[j++] = next;
break;
case '+':
case '-':
case '*':
case '/':
case '^':
while (!isEmpty() && precedence(stack[top]) >= precedence(symbol))
postfix[j++] = pop();
push(symbol);
break;
default:
postfix[j++] = symbol;
}
}

while (!isEmpty())
postfix[j++] = pop();
postfix[j] = '\0';
}

int precedence(char symbol)
{
switch (symbol)
{
// Higher value means higher precedence
case '^':
return 3;
case '/':
case '*':
return 2;
case '+':
case '-':
return 1;
default:
return 0;
}
}

void print()
{
int i = 0;
printf("The equivalent postfix expression is: ");
while (postfix[i])
{
printf("%c", postfix[i++]);
}
printf("\n");
}

void push(char c)
{
if (top == MAX - 1)
{
printf("Stack Overflow\n");
return;
}
top++;
stack[top] = c;
}

char pop()
{
char c;
if (top == -1)
{
printf("Stack Underflow\n");
exit(1);
}
c = stack[top];
top = top - 1;
return c;
}

int isEmpty()
{
if (top == -1)
return 1;
else
return 0;
}

yashchhaproo
Автор

But if associativity is right to left then there we don't have to pop out instead we have to directly push the incoming I guess this case is not tackled here request you to reply me back sir...so that I can clear my doubt.... thanks for this series 😀😊😊

kdoxfkck
Автор

a+b*c^d^e-f/g
SOLVE THIS!!
mention right to left associativity of ^ operator in upcoming videos!

r.prabhakaraarjun
Автор

sir there is a mistake in code you do t check precedence for power ^ from rigtht to lift you consider it like other from lift to right

here is my solution
short precedence(char symbol, short in=0)
{
switch (symbol)
{
// Higher value means higher precedence
case '^':
return 4-in;
case '/':
case '*':
return 2;
case '+':
case '-':
return 1;
default:
return 0;
}
}

while (!s.isEmpty()&&precedence(s.Peek(), 1)>=precedence(symbol))
{
+= s.pop();
}

mins 1 when ^ in stack so the precedence for ^ in out of stack

محمدعلي-فثخ
Автор

Sir, program file dedo na please
Mere program se sirf no. print ho rha h operator nhi

irfansari_
Автор

Great lecture... I think parameter should be passed to inTopost()

swarnalatha
Автор

Sir it is high time to increase speed of uploading 🙏

DeepakKumar-nkcv
Автор

Hi sir

I need some help to solve my problem in Computing theory.

sharafvip