#include <stdio.h>
#include <stdlib.h>
struct node 
{
    int info;
    struct node *link;
};
typedef struct node* NODE;
NODE insert_front(int ,NODE );
NODE delete_front(NODE );
void display(NODE );
int main()
{
    int ch,item;
    NODE first;
    first=NULL;
    while(1)
    {
        scanf("%d",&ch);
        switch (ch)
        {
            case 1:
                scanf("%d",&item);
                first=insert_front(item,first);
                break;
            case 2:
                first=delete_front(first);
                break;
            case 3:
                display(first);
                break;
            case 4:exit(0);
            default:
                printf("Invalid Choice");
        }
    }
}
NODE insert_front(int item,NODE first)
{
    struct node* temp;
    temp=(struct node*)malloc(1*sizeof(struct node));
    temp->info=item;
    temp->link=first;
    return temp;
}
NODE delete_front(NODE first)
{
    NODE temp;
    if(first==NULL)
    {
        printf("\nSTACK UNDERFLOW - CANNOT POP");
        return NULL;
    }
    else
    {
        temp=first;
        first=first->link;
        printf("\nPopped element from stack is %d",temp->info);
        free(temp);
        return first;
    }
}
void display(NODE first)
{
    NODE temp;
    if(first==NULL)
    {
        printf("\nEMPTY STACK - NOTHING TO DISPLAY");
        return;
    }
    printf("\nTHE ELEMENTS OF STACK ARE -\n");
    temp=first;
    while(temp!=NULL)
    {
        printf("%d",temp->info);
        temp=temp->link;
        printf("->");
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: