Ch4 - Chapter 4 ADTsStackandQueue CHAPTERGOALS To be able...

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

View Full Document Right Arrow Icon
C h a p t e r   4 ADTs Stack and Queue C H A P T E R   G O A L S To be able to describe a stack and its operations at a logical level To be able to demonstrate the effect of stack operations using a particular implementation of a stack To be able to implement the Stack ADT in an array-based implementation To be able to declare variables of pointer type To be able to access the variables to which pointers point To be able to create and access dynamically allocated data To be able to explain the difference between static and dynamic allocation of the space in which the elements of an abstract data type are stored To be able to use the C++ template mechanism for defining generic data types To be able to define and use an array in dynamic storage To be able to describe the structure of a queue and its operations at a logical level To be able to demonstrate the effect of queue operations using a particular implementation of a queue To be able to implement the Queue ADT using an array-based implementation 1
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   Chapter  4   ADTs Stack and  Queue Chapter Outline
Background image of page 2
Chapter 4    ADTs Stack and  Queue    3 Teaching Notes Stacks Chapter 4 demonstrates how the data design perspectives discussed in Chapter 2 can be applied to build new data structures: the stack and the queue. The stack is conceptually simple, easy to implement, and can be used in many applications. The format of this chapter (specification of the ADT, use of the data type in a short application, development of one or more implementations, comparison of alternative representations if appropriate, and, finally, use of the data type in a large application) is typical of the chapters in the text. The Logical Level The discussion of stacks begins with an intuitive definition through the illustration of some real- world stacks. These examples suggest the accessing function of stacks: last in, first out (LIFO). Next we discuss the logical operations that one would need to be able to use a stack—creating a new stack, making a stack empty, adding elements to a stack, removing elements from a stack, and determining if a stack is empty or full. We then define the structure and its set of operations in the Stack ADT Specification. You should point out the use of preconditions and postconditions in the Stack ADT Specification. The preconditions and postconditions answer the "what if" questions, whose misunderstood answers are frequent causes of program errors. Question : "What if the stack is empty when it is Popped?" Answer: "The preconditions of Pop state that the stack is not empty. Check it before you call Pop.” Note that if they want the stack operations to check for overflow and underflow conditions, the students must change the Stack ADT Specifications to reflect the change in interfaces, preconditions, and postconditions. The User Level
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.

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 / 16

Ch4 - Chapter 4 ADTsStackandQueue CHAPTERGOALS To be able...

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