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 stack = new Stack(); String infix = "1+8/7*8+4"; //infixe girdiimiz deer Console.WriteLine("nfix : " + infix);//infixi ekrana yazdryoruz String output= "";//postfix for (int i = 0; i < infix.Length; i++) { Char ch = infix[i];//infixdete karakterleri ch deikenine atar tek tek. if ((ch == '*') || (ch == '/') || (ch == '+') || (ch == '-')) {

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!