Assignment 4
Assignment 4
Problem 3. Write a program to reverse a string using two different techniques: stack and
recursion. For example, “hello” is converted to “olleh”.
#include <bits/stdc++.h>
using namespace std;
class Stack
{
public:
int top;
unsigned capacity;
char* array;
};
int n = strlen(str);
Stack* stack = createStack(n);
int i;
for (i = 0; i < n; i++)
push(stack, str[i]);
int main()
{
char str[51];
cout<<"Enter a string :";
gets(str);
reverse(str);
cout << "Reversed string is " << str;
return 0;
}