{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}


notes28 - StackListEntry top StakcList top = null void...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
file:///H|/pu.data/Desktop/0118.html Implementing Stack with a single linked list Linked List Stack Top -> 5 -> 3 -> 2 -> .. 5 3 2 - Top points to the node at the top of the stack - Push: adds a new node at the front of the list - Pop: removes a node from the front of list Example: Stack of element of type Object using a linked list class StackListEntry{ Object ob; StackListEntry next; } class StackList{
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: StackListEntry top; StakcList(){ top = null; } void push (object ob){ StackListEntry tmp = new StackListEntry(); tmp.ob = ob; tmp.next = top; top = tmp; } Object pop() throws StackEmptyException{ if (top == null){ throws new StackEmptyException(); } StackListEntry temp = top; top = tmp.next; return tmp.ob; } file:///H|/pu.data/Desktop/0118.html [2/3/2008 2:10:57 AM]...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online