Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

STACK

JohnYXJohnYX CebuPosts: 2Member

Can some one help me to make a function for push and pop for this code:

/PROGRAMMER: JOHN CARLO CAHIMAT & GLEEN SABULAAN PROJECT DESCRIPTION: Stack/

include<stdio.h>

define MAX 10

main(){ int a[MAX],count=0,choice=0,data,i;

clrscr();
while(choice!=3){
    clrscr();
    printf("STACK LIST\n");

    for(i=0;i<count&&count!=0&&count!=MAX+1;i++){
        printf(" %d ",a[i]);
    }
    printf("\n\n[1] PUSH");
    printf("\n[2] POP");
    printf("\n[3] EXIT");
    printf("\nEnter your choice: ");
    scanf("%d",&choice);

    if(choice==1){
        if(count>=MAX){
            clrscr();
            printf("STACK FULL");
            getch();
        }else {
            printf("Enter data: ");
            scanf("%d",&data);
            a[count]=data;
            count++;
        }

    } else if(choice==2){
        if(count<=0){
            clrscr();
            printf("STACK IS EMPTY");
            getch();
        } else {
            clrscr();
            count--;
            printf("\nPopped Value: %d",a[count]);
            a[count]=0;
            getch();
        }
    } else if(choice==3){
        exit(0);
    }
}

getch();

}

Sign In or Register to comment.