Thursday 13 October 2011

Algorithm of Stacks Using Linked


"Stacks using linked list"

1)start
2)define template<class T>
3)Define a class'stacks' with private data:
structure node containing 'ele'of type T and 'link'of type node* and
and public data:node* top,constructor for initialising top=NULL,functions push,pop() and display()
4)In function push define pointer t of node* type, do t->ele=ele.Check if top=NULL,if yes do top=t,t->link=NULL,else do t->link=top,top=t
5)In function pop check if top=NULL,if Yes print"underflow",return 0,else do top=top->link,return -1.
6)In function display do t=top,while(t!=NULL) print t->ele,do t=t->ele.
7)stop

No comments:

Post a Comment