Reversing a Stack with the help of another empty Stack

Reversing a Stack with the help of another empty StackGiven a Stack consisting of N elements, the task is to reverse the Stack using an extra stack.Examples:Input: stack = {1, 2, 3, 4, 5}Output:12345Explanation:Input Stack:54321Reversed Stack:12345Input: stack = {1, 3, 5, 4, 2}Output:13542Approach: Follow the steps below to solve the problem:Below is the implementation of the above approach.C++#include using namespace std;  void transfer(stack& s1,              stack& s2, int n){    for (int i = 0; i < n; i++) {                          int temp = s1.top();                  s1.pop();                  s2.push(temp);    }}  void reverse_stack_by_using_extra_stack(stack& s,                                        int n){    stack s2;      for (int i = 0; i < n; i++) {                          int x = s.top();                          s.pop();          transfer(s, s2, n - i - 1);        s.push(x);        transfer(s2, s, n - i - 1);    }}  int main(){    int n = 5;      stack s;    s.push(1);    s.push(2);    s.push(3);    s.push(4);    s.push(5);      reverse_stack_by_using_extra_stack(s, n);      for (int i = 0; i < n; i++) {        cout