0
1.2kviews
Write a program to reverse string using Stacks.
1 Answer
0
10views
#include <stdio.h>  
#include <string.h>  
#define max 100  
int top,stack[max];    
void push(char x){  
// Push operation  
  if(top == max-1){  
      printf("stack overflow");  
  }  else {  
      stack[++top]=x;  
  }  

}  
void pop(){  
// Pop operation  
  printf("%c",stack[top--]);  
}  
main()  
{  
 char str[]="sri lanka";  
 int len = strlen(str);  
 int i;  

for(i=0;i<len;i++)  
     push(str[i]);  

for(i=0;i<len;i++)  
   pop();  
}
Please log in to add an answer.