Sunday, February 16, 2020

Data Structure- 2. Stacks Push and POP Operation

As you know that in stack we always perform push and pop f an element from the top of the stack , here is the code to do the same

/******************************************************************************
Push and Pop Operation in Stack !               
@Mukesh Mann dated 16-02-2020
*******************************************************************************/
#include <stdio.h>
 int top=-1; // Delaring a Top variable initially pointing to -1
 int stack [10]; // a stack array of 10 elements

int main()
{
   
    // Push operation in stack  array
    for (int i=0; i<=10; i++)
    {
    top=top+1;
    stack[top]=i;
      }
     
   // Printing content of stack array
     for (int i=1; i<=10; i++)
     {
     printf(" The element in the stack are %d\n",stack[i]);  
     }
   
    // pop operation in stack array
   
    for (int i=1; i<=10; i++)
     {
     printf(" poping %d  element  %d\n",i, stack[top]);
     top=top-1;
     }

    printf(" After perfroming pop operation the content of stack is %d\n",stack[top]);
    
    return 0;
}

No comments:

Post a Comment

9_Regular Expressions

Regular expressions- Sometimes in HTML, the developer defines more than one class name ( that’s class input has more than one name Here ...