Stack revese using recursion


please check why it is giving segmentation fault

please reply …it will be very helpful

please reply…this is happening everytime …no one replies on time

I know the pain bro… i don’t get much help either ):
but i’ll help you

    while(n--) 
    {
        
        int x;
        cin>>x;
        s.push(x);
        reverse(s); //do the reverse(s) outside the while loop.
    }
    //reverse(s);
void insert_at_bottom(stack<int> &s,int x)
{
    if(s.empty())
    {
        s.push(x);
        return;
    }
    int y  = s.top();  //you copied the top element, you forgot to do s.pop();
    insert_at_bottom(s,x);  
    s.push(y);
}

@aayushmathur05
r u TA ?

if not then please help using personal chat only ,i thought u r ta and taking his doubt

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.