Sunday, August 22, 2010

POP operation

POP:

             The process of deleting an existing item from the top of the stack is called as POP       operation. On each attempt to delete the data, the value of the data at the top of the stack is retrieved and the value of the stack pointer will be decremented by one.

ALGORITHM:

      step1: check the for the stack underflow
           if TOP<0
                 {
                     Then print "Stack is empty and exit"
                  }
            else
                 {
                      Remove the data from the top of the stack
                  }

     step2:[delete an item from the top position of the stack]
 
            set STACK[TOP] = TOP;

    step3:[Decrement the pointer]

           set TOP = TOP-1;

PROGRAM:

      void pop()
          {
                  int item;
                    if(TOP == -1)
                        {
                          printf("The stack is empty");
                         getch();
                        exit(0);
                      }
                 else
                    {
                     item=STACK[TOP];
                     TOP=TOP-1;
                    }
            return(item);
          }