six.doc - Chapter 6 6.1 6.2 6.3 6.4 6.5 6.6 Stacks Stack Abstract Data Type Stack Applications Case Study Displaying a String in Reverse Order Case

six.doc - Chapter 6 6.1 6.2 6.3 6.4 6.5 6.6 Stacks Stack...

This preview shows page 1 - 3 out of 39 pages.

Chapter 6 Stacks 6.1 Stack Abstract Data Type 6.2 Stack Applications Case Study: Displaying a String in Reverse Order Case Study: Checking for Balanced Parentheses 6.3 Evaluating Expressions Case Study: Evaluating Postfix Expressions 6.4 Implementing Stack ADT 6.5 Additional Applications of Stacks Case Study: Converting from Infix to Postfix 6.6 Common Programming Errors Chapter Review In Chapters 6 through 10 we introduce several abstract data types of great importance to software engineers. As each abstract data type is introduced, study its attributes and operators very carefully. Look for similarities and differences between the new abstract data type and the abstract data types that we have already discussed in the text. This will help to identify abstract data types which are candidates for reuse via object inheritance. When we describe alternative methods of implementing an abstract data type pay close attention to the limitations imposed by the C++ language and those limitations which are present in the in the definition of the abstract data type itself. It is best to compare two implementations of the same abstract data type in terms of their relative execution times, the amount of memory required, and the ease with which they may be programmed. In this chapter we illustrate how to use an abstract data type known as a stack and how to implement a stack abstract data type as a C++ class. When we discussed recursion in Chapter 5, we introduced the stack as a useful data structure for storing the actual parameters passed in each call to a recursive function (see Section 5.1). A stack provides a convenient mechanism for storing information (or dishes in a cafeteria); we can access only the top item in a stack and we can do this only when data in the stack is to be accessed in the reverse order from which it was stored in stack. 6.1 Stack Abstract Data Type In this section we will discuss a data abstraction, the stack, that is very useful in computer science applications such as writing compilers. We already introduced the stack in Section 5.1 and discussed how stacks might be used to implement recursion. A stack is characterized by the property that at any one time only the top element of the stack is accessible. In a stack the top element of the stack is always the data value which was most recently stored in the stack. Sometimes this storage policy is known as "last-in, first-out" or LIFO. Some of the operations that we might wish to perform on a stack are summarized in Table 6.1. Table 6.1 Specification of Abstract Data Type Stack ---------------------------------------------------------------- Elements A stack consists of a collection of elements that are all the same data type. Structure
Image of page 1
The elements of a stack are ordered according to when they were placed on the stack. Only the element that was last inserted into the stack may be removed or examined. New elements are inserted at the top of the stack.
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 39 pages?

  • Spring '13
  • L
  • Infix notation, Reverse Polish notation, Stack ADT

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes