".C" file is available in downloadable format at :
https://drive.google.com/file/d/0ByF0OId1bLx6SzdZb1d2cEl4NnM/view?usp=sharing
(Open the link and click on the download arrow on the top right to download the file.)
Given below is the code for "C Program for Implementation of Stack using Array" :
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<stdlib.h>
#define size 10
typedef struct stack
{
int a[size];
int top;
}ob;
ob s; //object
void push()
{
int ele;
printf("\nEnter the ele to be inserted:\t");
scanf("%d", &ele);
if(s.top==size-1)
{
printf("Stack Overflow.");
}
else
{
s.top++;
s.a[s.top]=ele;
}
}
int pop()
{
if(s.top==-1)
{
printf("Stack Underflow");
return -1;
}
else
{
return --s.top;
}
}
void display ()
{
int d;
d=s.top;
while(d!=0)
{
printf(" %d ", s.a[d]);
d--;
}
printf("\n");
}
void main ()
{
int a, disp;
while(1)
{
printf("\n1. Push\n2. Pop\n3. Display.\n4. Exit.\n\nYour Choice:\t");
scanf("%d", &a);
switch (a)
{
case 1: push(); break;
case 2: s.top = pop(); break;
case 3: display (); break;
case 4: exit(0);
default: printf("\nHey, wrong choice\n"); break;
}
}
}
-------------------------------------------------------------------------------
No comments:
Post a Comment