PDF Archive

Easily share your PDF documents with your contacts, on the Web and Social Networks.

Share a file Manage my documents Convert Recover PDF Search Help Contact


Preview of PDF document datastructureunit3.pdf

Page 1 2 3 4 5 6 7 8 9 10 11 12 13

Text preview



int items[STACKSIZE];
The stack s may be declared by
struct stack s;
The stack items may be int, float, char, etc. The empty stack contains noelements and can therefore be
indicated by top= -1. To initialize a stack S to theempty state, we may initially execute
s.top= -1.
To determine stack empty condition,
if (s.top=-1)
stack empty;
el se
stack is not empty;
The empty(s) may be considered as follows:
int empty(struct stack *ps)
if(ps->top== -1)
el se
Aggregating the set of implementation-dependent trouble spots into small,easily identifiable units is an
important method of making a program moreunderstandable and modifiable. This concept is known as
modularization, inwhich individual functions are isolated into low-level modules whose propertiesare
easily verifiable. These low-level modules can then be used by more complexroutines, which do not have
to concern themselves with the details of the low-level modules but only with their function. The complex
routines maythemselves then be viewed as modules by still higher-level routines that use
themindependently of their internal details.
• Implementing pop operation
If the stack is empty, print a warning message and halt execution. Remove thetop element from the stack.
Return this element to the calling program
int pop(struct stack *ps)
Page 33