Basic Operations
Performed on Stack :
- · Create
- · Push
- · Pop
- · Empty
- · Full
Creating Stack:
·
Stack can be created by declaring the
structure with two members.
·
One Member can store the actual data
in the form of array.
·
Another Member can store the position
of the topmost element.
typedef struct stack {
int data[MAX];
int top;
}stack;
Push Operation on
Stack:
·
We have declared data array in the
above declaration. Whenever we add any element in the ‘data’ array then it will
be called as “Pushing Data on the Stack”.
·
Suppose “top” is a pointer to the top
element in a stack.
·
After every push operation, the value
of “top” is incremented by one.

Pop Operation on
Stack:
Whenever we try to remove element from the stack then the
operation is called as POP
Operation on Stack.▶
▶

Check Whether Stack is Empty
or Not ?
·
We are using Empty Function for Checking whether
stack is empty or not –
·
Function returns “True” if Stack is Empty.
·
Function returns “False” if Stack is Non-Empty.
·
Function Takes “Pointer to Stack”
Empty Function :
int empty(stack *s)
{
if(s->top == -1) //Stack is Empty
return(1);
else
return(0);
}stack;
Stack
int empty
(stack *s)
Return Type: Integer. [Empty
Stack Return 1 , Non Empty Stack Return 0 ]
Parameter: Address of
Variable of Type Stack .
Check Whether
Stack is Full or Not?
·
We are using Full Function for
Checking whether stack is full or not –
·
Function returns “True” if Stack is
Full
·
Function returns “False” if Stack is
Not Full.
·
Function Takes “Pointer to Stack”
Full Function:
int
full(stack *s)
{
if(s->top == MAX-1) //Stack is Full
return(1);
else
return(0);
}
int
full (stack *s)
Return Type: Integer. [If full Stack Return 1 , not full
Stack Return 0 ]
Parameter: Address of Variable of Type Stack.
No comments:
Post a Comment