February 25, 2014

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);



}
}

}

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.


    goldenslot casino
    บาคาร่าออนไลน์
    gclub casino


    thank you!

    ReplyDelete
  4. Nice information.. Thanks for sharing. DACCESS provides you designed and developed access control system on open flexible technology to provide real-time monitoring, management and control of your access system. Daccess also offers developed parking management system, CCTV camera

    ReplyDelete

C program to Read From a File

#include <stdio.h> #include <stdlib.h> void main() {     FILE *fptr;     char filename[15];     char ch;   ...