Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Stack using array

Posted By: Adalrik Fischer     Category: C Programming     Views: 8189

Program of stack using array.

Code for Stack using array in C Programming

#include<conio.h>
#include<stdio.h>
#define N 5

void main()
{
    int a[N]={0};
    int sp=-1,ch,n,i;

    clrscr();
    while(ch!=5)
    {
        printf("\n\t 1.PUSH.");
        printf("\n\t 2.POP.");
        printf("\n\t 3.DISPLAY.");
        printf("\n\t 4.PEEP A PARTICULAR VALUE.");
        printf("\n\t 5.EXIT ");
        printf("\n\t ENTER UR CHOICE :::: ");

        scanf("%d",&ch);

        if(ch==1)
        {
            if(sp>=N)
            {
                printf("\n\t STACK FULL ");
                break;
            }
            printf("\n\t ENTER DATA:::: ");
            scanf("%d",&n);
            sp++;
            a[sp]=n;
        }
        if(ch==2)
        {
            printf("\n\t POPPED VALUE ::: %d",a[sp]);
            a[sp]=0;
            sp--;
        }
        if(ch==3)
        {
            for(i=sp;i>=0;i--)
            {
                printf("\n\t %d",a[i]);
            }
        }
    }
    getch();
}

  
Share: 


Didn't find what you were looking for? Find more on Stack using array Or get search suggestion and latest updates.

Adalrik Fischer
Adalrik Fischer author of Stack using array is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!