ProAnswers.org

algorithm Checking if the stack is empty

algorithm Checking if the stack is empty

[b]Checking if a stack is empty

Array implementation
    [/b]
int isEmpty(stack *stk){
    if(stk -> top == -1)
        return 1; //stack is empty
    else
        return 0; //stack is not empty
}

[b]Linked list implementation[/b]

    
int isEmpty(stack *stk){
    if(stk -> top == NULL)
        return 1; //stack is empty
    else return 0;    //stack is not empty
}