ช่วยด้วยยยยคะ ! มีใครพอช่วยได้ไหมคะ

#include<stdio.h>
#include<stdlib.h>
struct node
    {
    int info;
    struct node *link;
    }*top = NULL;
    
void push(int num);
int pop();
void display();

main()
{
    int choice,num;
    while(1)
    {
        
        printf("\n1.Push\n");
        printf("2.Pop\n");
        printf("3.Display\n");
        printf("4.Exit\n\n");
        printf("Enter your choice : ");
        
        scanf("%d",&choice);
           printf("===============\n\n");

           switch(choice)
           {
                case 1:
                             printf("Enter your Data : \n");
                             scanf("%d",&num);
                         push(num);
                         break;
                        
             case 2:
                         num = pop();
                          break;
                         
             case 3:
                         display();
                          break;
                         
             case 4:
                         exit(1);
                         
                         
             default:    printf("Invalid Input\n");
        }
    }
}

void push(int num)

    {
        
        struct node *temp;
        temp = (struct node *)malloc(sizeof(struct node));
        if (temp==NULL)
        {
            printf("stack overflow\n");
            return;
        }
        temp->info =num;
        temp->link =top;
        top = temp;
    }

    
int pop()
{
    struct node *temp;
    int num;
    if (top==NULL)
    {
        printf("stack underflow\n");
        return(0);
        
    }
    
        temp =top;
        num =top->info;
        top  =top->link;
        free (temp);
        printf("Deleted: %d\n",num);
        return (num);
    }
        
void display()
{
    struct node *p;
    if (top==NULL)
        {
            printf("stack underflow\n");
            return;
        }
        
        printf("\n stack is\n");
        p=top;
        while (p!=NULL)
            {
                printf("%d\n",p->info);
                p=p->link;
            }
        }
แก้ไขข้อความเมื่อ
แสดงความคิดเห็น
Preview
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่