Saturday, September 3, 2011

Stack


/* stack in an array */

#include<stdio.h>
#include<stdlib.h>
#include "stack1.h"   //implementation of static stack
int main()
{
stack s;
char x;
init(&s);
printf("\nEnter a string : ");
while((x=getchar())!='\n')
 {
    if(!full(&s))
 push(&s,x);
    else
      {
 printf("\nStack is full ");
 exit(0);
      }
 }
printf("\nReverse string : ");
while(!empty(&s))
 {
x=pop(&s);
printf("%c",x);
 }
 }

No comments:

Post a Comment