Thursday 13 October 2011

Algorithm of Stacks Using Array


"Stacks using array"

1)start
2)Define constant max=10;
3)define template<class T>
4)Define a class'stacks' with private data:
array stack[max] of template type integer top
and public data:constructor for initialising top with function push(0,pop() and display()
5)In function push check if top=max-1,If yes return 0,else do top++,stack[top]=ele,return 1.
6)In function pop check if top=-1,if so return 0.
eles do top--,return 1.
7)In function display print stack[i] where i runs from top to 0.
8)stop

No comments:

Post a Comment