C program for Stack implementation using array

#include "stdio.h"
#include "conio.h"

#define size 5

int stack[size] = {0};

int top = -1;

void push(int value)
{
if(top < size)
{
top++;
stack[top] = value;
}
else
{
printf("Stack overflow \n");
}
}

void pop()
{
if(top >= 0)
{
printf("The popped element is:\t %d \n", stack[top]);
stack[top] = 0;
top--;
}

else
{
printf("Stack underflow \n");
}


}
void display()
{

                 int i;

for(i=size - 1;i>=0;i--)
{
printf(" %d \n",stack[i]);
}
}

void tos()
{
printf("The value at top is %d", stack[top]);
}

int main()
{

int i,j, ch=0 ,value = 0;

while(1)
{
printf("\n Please Enter the choice. \n");
printf("1 for push\n 2 for pop \n 3 for display\n 4 for top \t  \n 5 for exit");
scanf("%d",&ch);

switch(ch)
{
case 1:
printf("\n Please Enter the number to be inserted: \t");
scanf("%d", &value);
push(value);
break;

case 2:

pop();

break;

case 3:

display();

break;


case 4:
tos();

break;

case 5:

exit(0);



}
}

}

Reactions:

6 comments:

  1. Platinum FREE Download iTel Dialer with DU solution.Must say that you are really going like a skyrocket in blog-o-sphere. So depth and informative article, is something like worth reading and sharing. Creating unique content takes efforts and dedication, Great article bro, keep continue follow this way to success :) Platinum FREE Download Business Voip Solutions with DU solution.

    ReplyDelete
  2. नोटबंदी के 50वें दिन, मोदी सरकार के फैसले से निराश हैं जनता
    Readmore todaynews18.com https://goo.gl/NJUQY9

    ReplyDelete
  3. Learning new technolgoy would help oneself at hard part of their career. And staying updated is the only way to survive in current position. Your content tells the same. Thanks for sharing this information in here. Keep blogging like this.
    PHP Training in Chennai

    ReplyDelete