STACK - Programmers Heaven

Howdy, Stranger!

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

Categories

STACK

JohnYXJohnYX CebuPosts: 3Member

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.