STACK implementation using ARRAY in C

/* stack implementation through array */

#include<stdio.h>

#define MAXSIZE 5

int stack[MAXSIZE];
int top=0; // index pointing to top of stack

void main()
{
void push();
void pop();
void display();
int will=1, i;

while(1)
{
printf(“\n\n\n MAIN MENU:\n\n\n 1. PUSH \n 2. POP \n 3. EXIT \n\n ENTER YOUR CHOICE:”);
scanf(“%d”, &will);
switch(will)
{
case 1:
push();
display();
break;
case 2:
pop();
display();
break;
case 3:
exit(0);
break;
default:
printf(“Invalid Choice”);
}
}  //end of outer while
} //end of main

void push()
{
int num;
if(top>=MAXSIZE)
{
printf(“\n STACK FULL”);
return;
}
else
{

printf(“\n\n ENTER THE STACK ELEMENT:”);
scanf(“%d”, &num);
stack[top++]=num;
}
}

void pop()
{
if(top>0)
top–;
}

void display()
{
int i;
if(top<=0)
printf(“\n\n STACK EMPTY”);

else
for(i=top-1;i>=0;i–)
{
printf(“\n\n %d”, stack[i]);
if(i==(top-1))
printf(“—>TOP”);

}
}

Advertisements

4 thoughts on “STACK implementation using ARRAY in C

  1. maneesh says:

    faadu….meri jaan..jhaakaaaas…
    🙂

  2. Amit says:

    keep up the good work!!! badiya!!

  3. […] STACK implementation using ARRAY in C (sumitpathak.wordpress.com) […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s