Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

stacks and its operaaton code

#include<stdio.h>
 
#include<stdlib.h>
  
#define Size 4 
  
int Top=-1, inp_array[Size];
void Push();
void Pop();
void show();
  
int main()
{
    int choice;
     
    while(1)    
    {
        printf("
Operations performed by Stack");
        printf("
1.Push the element
2.Pop the element
3.Show
4.End");
        printf("

Enter the choice:");
        scanf("%d",&choice);
         
        switch(choice)
        {
            case 1: Push();
                    break;
            case 2: Pop();
                    break;
            case 3: show();
                    break;
            case 4: exit(0);
             
            default: printf("
Invalid choice!!");
        }
    }
}
  
void Push()
{
    int x;
     
    if(Top==Size-1)
    {
        printf("
Overflow!!");
    }
    else
    {
        printf("
Enter element to be inserted to the stack:");
        scanf("%d",&x);
        Top=Top+1;
        inp_array[Top]=x;
    }
}
  
void Pop()
{
    if(Top==-1)
    {
        printf("
Underflow!!");
    }
    else
    {
        printf("
Popped element:  %d",inp_array[Top]);
        Top=Top-1;
    }
}
  
void show()
{
     
     
    if(Top==-1)
    {
        printf("
Underflow!!");
    }
    else
    {
        printf("
Elements present in the stack: 
");
        for(int i=Top;i>=0;--i)
            printf("%d
",inp_array[i]);
    }
}
Source by www.journaldev.com #
 
PREVIOUS NEXT
Tagged: #stacks #operaaton #code
ADD COMMENT
Topic
Name
9+9 =