0% found this document useful (0 votes)
20 views

Stack Using Arrays

Uploaded by

eloziiopfoze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Stack Using Arrays

Uploaded by

eloziiopfoze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#define MAX 10

int top=-1;
int stack[MAX];
int full, empty=1;

void print(void);
void push(int);
int pop(void);

void main(void)
{
int item, ch=1;
clrscr();

while(ch)
{
printf("\n1. Push Item");
printf("\n\n2. Pop Item");
printf("\n\n3. Print Stack");
printf("\n\n4. Exit");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter the item to push");
scanf("%d",&item);
push(item);
break;
case 2:
item=pop();
printf("Poped item is %d", item);
break;
case 3:
print();
break;
case 4:
break;
}
scanf("%d",&ch);
}
}
void push(int x)
{
if(full)
{
printf("Stack is full\n");
return;
}
else
{
top=top+1;
stack[top]=x;
empty=0;
}
if(top==MAX)
full=1;
return;
}

int pop(void)
{
int x;
if(empty)
{
return -1;
}
else
{
x=stack[top];
top--;
if(top==-1)
empty=1;
return x;
}
}
void print(void)
{
int i;
if(empty)
{
printf("Stack is empty");
return;
}
else
{
for(i=0; i<=top; i++)
printf("%d, ",stack[i]);
return;
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy