DEV Community

JAIKUMAR DEWANGAN
JAIKUMAR DEWANGAN

Posted on

Stack

#include<bits/stdc++.h>

using namespace std;

void addStrIntoStack( string str)
{ 
    int n = str.length(); 
    string rev = "";
    stack <char>st ; 

    for(int i=0; i<n; i++)
    {
       st.push(str[i]) ;
    }

  // reverse 
  while(!st.empty())
  {
     if(st.top() == 'a' ||st.top() == 'e' || st.top() == 'i'||st.top() == 'o' ||st.top() == 'u' )
      {
           char ch = st.top() - 32;
             rev = rev + ch;
      } 
  else{ rev = rev + " " + st.top();}

    st.pop(); 
  }

  cout<<"string hai "<<rev; 

}

int main(){

  string s = "abcde" ; 

   addStrIntoStack( s);






    return 0; 
}
Enter fullscreen mode Exit fullscreen mode
#include <bits/stdc++.h>

using namespace std;

stack<char> addStrIntoStack(string str)
{
    int n = str.length();
    string rev = "";
    stack<char> st;

    for (int i = 0; i < n; i++)
    {
        st.push(str[i]);
    }

    // reverse
    return st;
}

string reverseStack(stack<char> &st, string rev)
{
    if (st.empty())
    {
        return rev;
    }

 rev = rev + st.top();
    st.pop();

    return reverseStack(st, rev);
}

int main()
{

    string s = "abcde";

    stack<char> st = addStrIntoStack(s);

    string rev = "";

    rev = reverseStack(st, rev);

    cout <<"ye hai :"<< rev;

    return 0;
}
Enter fullscreen mode Exit fullscreen mode
#include <bits/stdc++.h>
using namespace std;

string prefix_to_infix(string str){
    stack<string> st;

    for(int i=str.length()-1;i>=0;i--) {
        if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')){
            string s ="";
            s+=(str[i]); // string me nhi aa rha tha 
            st.push(s);
        }
        else{
            string a = st.top();
            st.pop();
            string b = st.top();
            st.pop();
            string c = '('+a+str[i]+b+')';
            st.push(c);
        }
    }
    return st.top();
}
int main(){

    string s ;
    cin>>s;
    string str = prefix_to_infix(s);
    cout<<str;
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay