From 40e0d9d58ed176fb5631ab34e81339a1902e360c Mon Sep 17 00:00:00 2001 From: kanan010506 Date: Sat, 11 Oct 2025 14:08:22 +0530 Subject: [PATCH] Postfix to Infix conversion --- CPP/Stacks_Queues/postfixToInfix.cpp | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 CPP/Stacks_Queues/postfixToInfix.cpp diff --git a/CPP/Stacks_Queues/postfixToInfix.cpp b/CPP/Stacks_Queues/postfixToInfix.cpp new file mode 100644 index 0000000..3a7b72a --- /dev/null +++ b/CPP/Stacks_Queues/postfixToInfix.cpp @@ -0,0 +1,32 @@ +//postfix to infix conversion +#include +#include +#include +using namespace std; + +string postfixToInfix(string s){ + int i=0; + int n = s.size(); + stack st; + while(i='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z') || (s[i]>='0' && s[i]<='9')){ + st.push(string(1,s[i])); + } + else{ + string tempB = st.top(); + st.pop(); + string tempA = st.top(); + st.pop(); + st.push("(" + tempA + s[i] + tempB +")"); + } + i++; + } + return st.top(); +} + +int main(){ + string s = "AB-DE+F*/"; + string ans = postfixToInfix(s); + cout<