/*——————–*/
include”stdio.h”
define MAX 25
void push(int t);
int pop(void);
int top=-1,t,rt,lt,c,val;
int stack[MAX];
void push(int t)
{
top++;
stack[top]=t;
}
int pop(void)
{
int r;
if(top==-1)
{
printf(“stack empty\n”);
return 0;
}
else
{
r=stack[top];
top–;
return r;
}
}
/*——————–*/
/* To implement a stack using linked list – MAIN FILE*/
/* Header file inclusion */
#include “STACKLINK.h”
/* Global variables */
int message;
/* MAIN FUNCTION */
void main(void)
{
int option;
create();
do
{
clrscr();
userinfo(message);
printf(“\n#######MENU#######\n”);
printf(“\n1.Push\n2.Pop\n3.Print stack\n4.Exit”);
printf(“\nType in your options\t:”);
scanf(“%d”,&option);
switch(option)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
print();
break;
default:
message=3;
break;
}
}while(option!=4);
}
/*——————–*/
/* Implementation of stack using linked list – HEADER FILE */
#include
#include
/* THE NODE STRUCTURE */
struct NodeStack
{
int content;
struct NodeStack *link;
};
/* Global variables */
int count=0,message;
/* Nodes used */
struct NodeStack *head,*s,*s1,*temp;
/* Functions used */
void push();
void pop();
void print();
void userinfo();
void create();
/* Create a head node */
void create()
{
head=(struct NodeStack*)malloc(sizeof(struct NodeStack));
head->content=0;
head->link=NULL;
}
/* Push */
void push()
{
int value;
printf(“\nEnter the value\t:”);
scanf(“%d”,&value);
if(count==0)
{
s1=(struct NodeStack*)malloc(sizeof(struct NodeStack));
head->link=s1;
s1->content=value;
s1->link=NULL;
count++;
message=1;
}
else
{
s=(struct NodeStack*)malloc(sizeof(struct NodeStack));
s1=head;
while(s1->link!=NULL)
{
s1=s1->link;
}
s->content=value;
s->link=NULL;
s1->link=s;
count++;
message=1;
}
}
/* Pop */
void pop()
{
int temp;
s1=head;
if(count==0)
{
message=4;
}
else
{
while(s1->link!=NULL)
{
s=s1;
s1=s1->link;
}
temp=s1->content;
s1->content=NULL;
s->link=NULL;
free(s1);
count–;
printf(“\n%d will be popped out of the stack “,temp);
getch();
message=2;
}
}
/* Print the stack */
void print()
{
if(count==0)
printf(“Stack empty”);
else
{
s=head;
while(s->link!=NULL)
{
s=s->link;
printf(“\n%d”,s->content);
}
printf(“\t\t
#include
#include
#define max 20
int top=-1;
int stack[max];
int size;
int isFull();
int isEmpty();
void create();
int makeEmpty(int *stack);
int push(int *stack,int data);
int pop(int *stack);
int print(int *stack);
void create()
{
int i;
printf(“\nEnter the no. of elements limit upto 10″);
scanf(“%d”,&size);
top++;
for(i=0;i=0;i–)
printf(“%d “,stack[i]);
return 1;
}
}
int makeEmpty(int *stack)
{
int a;
if(isEmpty(stack))
return 0;
else
{
while(isEmpty()!=1)
a=pop(stack);
return a;
}
}