Tuesday, July 19, 2011

Stack

#include

#include

# define stacksize 100

#include

struct stack

{

char name[81];

char address[81];

};

struct arr

 {

 struct stack s[stacksize];

 int top;

 };

 void push(struct arr *ps,int x)

 {

  if(ps->top==stacksize-1)

   {

    printf("stack is overflow:");

     exit(0);

    }

    ps->top++;

    ps->s[ps->top]=x;

  }

  int pop(struct stack *ps)

  {

   if(ps->top==-1)

   {

     printf("stack is underflow");

     exit(0);

    }

    x=ps->s[ps->top];

    ps->top--;

    return x;

   }

   void display(struct satck *ps)

   {

     if(ps->top==-1)

      {

       printf("stack is underflow");

       exit(0);

       }

      for(i=ps->top;i>=0;i--)

       {

    printf("\n name\n",ps->s[i].name);

    printf("\n address\n",ps->s[i].address);

    printf("-----------------");

       }

   }

  void main()

  {

   struct stack s;

   struct arr ps;

   int ch;

   ps.top=-1;

   clrscr();

   do

   {

     printf("\n1.push");

     printf("\n2.pop");

     printf("\n3 display");

     printf("enter choice");

     fflush(stdin);

     scanf("%d",&ch);

     switch(ch)

      {

       case :printf("enter name");

         fflush(stdin);

         scanf("%s",&s,name);

   ps->s