Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- int x;
- Console.Write("inserire :");
- string op = Console.ReadLine();
- string ris="";
- Stack<string> num = new Stack<string>();
- string[] arr = op.Split(' ');
- for (int i = 0; i < arr.Length; i++)
- {
- switch (arr[i])
- {
- case "+":case "-":case "*":case "/":case "^":
- {
- foreach (var a in num)
- {
- if (a == "(")
- {
- int last = ;
- }
- /*if (LaCassssaa.controllo(arr[i]) < LaCassssaa.controllo(a))
- {
- foreach (var b in num)
- {
- if (b == "(")
- {
- string cestino = num.Pop();
- break;
- }
- else
- ris += num.Pop();
- }
- }
- }*/
- num.Push(arr[i]);
- break;
- }
- case "(":
- {
- num.Push(arr[i]);
- break;
- }
- case ")":
- {
- foreach (var b in num)
- {
- if (b == "(")
- break;
- else
- ris += b;
- }
- break;
- }
- case "0":
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- case "6":
- case "7":
- case "8":
- case "9":
- {
- ris += arr[i];
- break;
- }
- default:
- {
- break;
- }
- }
- }
- Console.WriteLine(ris);
- }
- }
- static public int controllo(string a)
- {
- switch (a)
- {
- case "+":
- {
- return 1;
- }
- case "-":
- {
- return 1;
- }
- case "*":
- {
- return 2;
- }
- case "/":
- {
- return 2;
- }
- case "^":
- {
- return 3;
- }
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement