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]); } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program to reverse a string using stack
need an explanation for this answer? contact us directly to get an explanation for this answer