Q:

Reverse string using stack

0

Here we are going to reverse a string using stack implemented using array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to reverse a string using stack

#include<stdio.h>
#include<string.h>
#define max 50
void main()
{
char str[max],stack[max];
int i,length,top=-1;
printf("Enter a string:");
gets(str);
length=strlen(str);
for(i=0;i<length;i++)
{
top++;
stack[top]=str[top];
}
for(i=length-1;i>=0;i--)
{
printf("%c",stack[i]);
}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now