stack algo using array

I m very confused on implementation of stack in C using array..
I have made following algo..please check if i m right!!

Initialise array a[100], top=-1 //let say size of array=100
input size of stack
push(arr,x,&top,size)
pop(arr,&top)

push(*arr,x,*top,size)
{
if top!=size-1
arr[top+1]=x
top++
}

pop(*arr,*top)
{
if top!=-1
arr[top]=NULL
top--
}

and plz tell me what is the need to make functions like isEmpty(), isFull() and stackTOP() when i can manage without them??
Last edited on
sme1 plz reply...m not able to proceed further..stuck at stacks!!
You need a size variable to track how many elements are currently in the stack and a maxSize variable so that you can check when it's full.

isEmpty() is implemented by simply checking if size == 0 and is Full() is implemeted by check if size == maxSize. Hope that helps you move forward. You don't really need sentinel values in the stack.
Last edited on
Topic archived. No new replies allowed.