stack - STACK A stack is a collection of items into which...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
STACK A stack is a collection of items into which new items are inserted and from which items are deleted at one end (called the top of the stack). Different implementations are possible; although the concept of a stack is unique. Example : Trays in the cafeteria. Two primary operations: 1. push : adds a new item on top of a stack. 2. pop : removes the item on the top of a stack Stack is also known as push-down list LIFO (Last In First Out): order of addition and deletion of items from a stack. 1 top
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A stack is a dynamic structure. It changes as elements are added to and removed from it. 2 Insert: A B C D E F Delete: F E D F E D C B A top C B A top
Background image of page 2
Data Structure A stack can be implemented as a constrained version of a linked list. A stack is referenced via a pointer to the top element of the stack. The link member in the last node of the stack is set to NULL to indicate the bottom of the stack. Example: - stackptr points to the top of the stack. Note that stacks and linked lists are represented identically. The difference is that insertions and deletions occur anywhere in a linked list, but only at the top of a stack. Function
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

stack - STACK A stack is a collection of items into which...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online