Loading, please wait...

A to Z Full Forms and Acronyms

Reverse string using stack

Oct 03, 2019 #stack #array #reverse #string, 1502 Views
Here we are going to reverse a string using stack implemented using array

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]);
}
}
A to Z Full Forms and Acronyms

Related Article