hi guys can any one work out a program for stack in c..for push and pop asap

xavier666 commented: This attitude will not work here +0

Recommended Answers

All 2 Replies

Sure, I can. It's simple. And fast to do. Why?

you want it for static array or dynamic array !!

here is algorithm for you


1. ask user what he wants to do push or pop

2.in pop check whether stack is empty or not if not then pop the last value in stack and decrement the stack count else show "STACK EMPTY"

3.in Push check stack is full or not if full show "STACK FULL" else
take value in stack and increment the stack counter

eg:-

void Push(int k)
{
if(stackCounter==MAX)
{
printf("STACK FULL");
}
else
{
a[stackCounter]=k;
stackCounter++;
}
}

int pop()
{
if(stackCounter!=0)
{int k=a[stackCounter];
--stackCounter;
}
else
{
printf("STACK EMPTY");
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.