IMPLEMENTATION OF STACK USING LINKED LISTS

#include
#include
struct node
{
    int info;
    struct node *ptr;
}*top,*top1,*temp;
int topelement();
void push(int data);
void pop();
void display();
void destroy();
void stack_count();
void create();
int count = 0;
void main()
{
    int no, ch, e;
    printf("\n 1 - Push the element");
    printf("\n 2 - Pop the element");
    printf("\n 3 - Display the Top element");
    printf("\n 4 - Exit");
    printf("\n 5 - Dipslay the stack");
    printf("\n 6 - Stack Count");
    printf("\n 7 - Empty the stack");
    create();
    while (1)
    {
        printf("\n Enter choice : ");
        scanf("%d", &ch);

        switch (ch)
        {
        case 1:
            printf("Enter data : ");
            scanf("%d", &no);
            push(no);
            break;
        case 2:
            pop();
            break;
        case 3:
            if (top == NULL)
                printf("Stack is empty");
            else
            {
                e = topelement();
                printf("%d is the top element\n ", e);
            }
            break;
        case 4:
            exit(0);
        case 5:
            display();
            break;
        case 6:
            stack_count();
            break;
        case 7:
            destroy();
            break;
        default :
            printf("Please enter correct choice  ");
            break;
        }
    }
}
void create()
{
    top = NULL;
}
void stack_count()
{
    printf("\n The elements in stack are %d", count);
}
void push(int data)
{
    if (top == NULL)
    {
        top =(struct node *)malloc(1*sizeof(struct node));
        top->ptr = NULL;
        top->info = data;
    }
    else
    {
        temp =(struct node *)malloc(1*sizeof(struct node));
        temp->ptr = top;
        temp->info = data;
        top = temp;
    }
    count++;
}
void display()
{
    top1 = top;

    if (top1 == NULL)
    {
        printf("Stack is empty");
        return;
    }

    while (top1 != NULL)
    {
        printf("%d\n", top1->info);
        top1 = top1->ptr;
    }
 }
void pop()
{
    top1 = top;
    if (top1 == NULL)
    {
        printf("The Stack is empty\n ");
        return;
    }
    else
        top1 = top1->ptr;
    printf("%d is the popped value \n ", top->info);
    free(top);
    top = top1;
    count--;
}
int topelement()
{
    return(top->info);
}
void destroy()
{
    top1 = top;
    while (top1 != NULL)
    {
        top1 = top->ptr;
        free(top);
        top = top1;
        top1 = top1->ptr;
    }
    free(top1);
    top = NULL;
    printf("All the elements in the stack are removed\n ");
    count = 0;
}