Ch4 - C Plus Data Structures Nell Dale Chapter 4 ADTs Stack...

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

View Full Document Right Arrow Icon
1 C++ Plus Data Structures Nell Dale Chapter 4 ADTs Stack and Queue Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Stacks of Coins and Bills
Background image of page 2
3 What is a Stack? Logical (or ADT) level: A stack is an ordered group of homogeneous items (elements), in which the removal and addition of stack items can take place only at the top of the stack. A stack is a LIFO “last in, first out” structure.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Stacks of Boxes and Books TOP OF THE STACK TOP OF THE STACK
Background image of page 4
Stack ADT Operations MakeEmpty -- Sets stack to an empty state. IsEmpty -- Determines whether the stack is currently empty. IsFull -- Determines whether the stack is currently full. Push (ItemType newItem) -- Adds newItem to the top of the stack. Pop (ItemType& item) -- Removes the item at the top of the stack and returns it in item. 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
ADT Stack Operations Transformers MakeEmpty Push Pop Observers IsEmpty IsFull change state observe state 6
Background image of page 6
//---------------------------------------------------------- // SPECIFICATION FILE (stack.h) //---------------------------------------------------------- #include "bool.h" #include "ItemType.h" // for MAX_ITEMS and // class ItemType definition class StackType { public: StackType( ); // Default constructor. // POST: Stack is created and empty. void MakeEmpty( ); // PRE: None. // POST: Stack is empty. bool IsEmpty( ) const; // PRE: Stack has been initialized. // POST: Function value = (stack is empty) 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
// SPECIFICATION FILE continued (Stack.h) bool IsFull( ) const; // PRE: Stack has been initialized. // POST: Function value = (stack is full) void Push( ItemType newItem ); // PRE: Stack has been initialized and is not full. // POST: newItem is at the top of the stack. void Pop( ItemType& item ); // PRE: Stack has been initialized and is not empty. // POST: Top element has been removed from stack. // item is a copy of removed element. private: int top; ItemType items[MAX_ITEMS]; // array of ItemType }; 8
Background image of page 8
9 Private data value ComparedTo Print Initialize class ItemType ItemType Class Interface Diagram
Background image of page 9

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

View Full DocumentRight Arrow Icon
//------------------------------------------------------- // IMPLEMENTATION FILE (Stack.cpp) //------------------------------------------------------ // Private data members of class: // int top; // ItemType items[MAX_ITEMS]; //------------------------------------------------------- #include “bool.h” #include “ItemType.h” StackType::StackType( ) //------------------------------------------------ // Default Constructor //------------------------------------------------ { top = -1; } 10
Background image of page 10
(Stack.cpp) //---------------------------------------------------------- void StackType::MakeEmpty( ) //--------------------------------------------------- // PRE: None. // POST:
Background image of page 11

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

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

This note was uploaded on 06/13/2011 for the course CSC 280 taught by Professor Lebre during the Spring '04 term at Moraine Valley Community College.

Page1 / 75

Ch4 - C Plus Data Structures Nell Dale Chapter 4 ADTs Stack...

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

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