#include<stdio.h>
#include<stdlib.h>
struct node
{
    int data;
    struct node*next;
};
struct node*top=0;
void push(int x)
{
    struct node*newnode;
    newnode=(struct node*)malloc(sizeof(struct node));
    newnode->data=x;
    newnode->next=top;
    top=newnode;
}
void pop()
{
    struct node*temp;
    temp=top;
    if(top==0)
    {
        printf("the stack is empty");
    }
    else
    {
        printf("%d",top->data);
        top=top->next;
        free(temp);
    }
}
void display()
{
    struct node*temp;
    if (top==0)
    {
        printf("the stack is empty");
    }
    else
    {
        temp=top;
        while(temp!=0)
        {
            printf(" %d",temp->data);
            temp=temp->next;
        }
    }
}
void peek()
{
    if(top==0)
    printf("the stack is empty");
    else
    {
        printf("\nPeek element is: %d",top->data);
    }
}
void main()
{
    push(2);
    push(3);
    push(10);
    display();
    peek();
}

Embed on website

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