Write a program to reverse a string using Stack.
Sample Input
hello dinesh
Sample Output
hsenid olleh
code👇👇👇👇👇👇👇👇👇👇👇
#include<stdio.h>
#include<string.h>
char stack[1000];
int top=-1;
void push(char item){
top=top+1;
stack[top]=item;
}
void pop(){
printf("%c",stack[top]);
top--;
}
void main(){
int i,n;
char c[1000],b[1000];
fgets(c,1000,stdin);
n=strlen(c);
for(i=0;i<n-1;i++)
push(c[i]);
for(i=0;i<n-1;i++)
pop();
}
No comments:
Post a Comment