Question: We should convert code C# to Python using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace infixToPostfix { class Program { static void
We should convert code C# to Python
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace infixToPostfix { class Program { static void Main(string[] args) { Stack
if (stack.Count!=0)// stack bo deil ise. { while (stack.Count!=0)// stack bo deilse bu dngye gir. { Char k = stack.Peek();//stack in en stndeki eleman if (Oncelik(k, ch) == false)//ncelii false ise { output += stack.Pop(); } else //true dner ise { break; } } stack.Push(ch);//dng bittiinde karakteri stacke pushlar
} else //stack bo ise direk push { stack.Push(ch); } } else //ch deikeni say ise { output += ch; // say ise direk postfixe at. } } /*Console.WriteLine("Stack eklenmeden Output : " + output); Console.Write("Stack items: ");*/ foreach (Char s in stack)// en son stackte kalanlar tek tek postfixe yolla. { output += s; } Console.WriteLine(" Postfix : "+ output);//en son postfixi ekrana yazdryoruz. Console.ReadKey();
/*int sonuc = int.Parse(infix); Console.WriteLine("Sonu : "+sonuc); Console.ReadKey();*/
} public static bool Oncelik(char a,char b)//iki karakterlerin nceliini karlatryoruz. { //a stackin en stndeki, b srada gelen. if (a == '-' || a == '+') return true; if (a == '*' || a == '/') { if (b == '*' || b == '/') return true; else return false;// - veya + olduunda.
}
else return true;
}
} }
Thank you
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
