lecture3-1 - ReviewofStacksandQueues Dr.YingwuZhu OurFocus

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

View Full Document Right Arrow Icon
    Review of Stacks and Queues Dr. Yingwu Zhu
Background image of page 1

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

View Full DocumentRight Arrow Icon
    Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of  Queue class, see Textbook for details!
Background image of page 2
    How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation  Removing an item Pop operation Properties Ordered collection of items Be accessed at only the top
Background image of page 3

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

View Full DocumentRight Arrow Icon
    Building a Stack Class Design a stack class   stack.h (header file) Implement the stack class   stack.cpp (implementation  file)
Background image of page 4
    Building a Stack Class Need to determine the  data structure  to store data items  (array or linked list?) Need to determine the  algorithms  to perform operations  on the data items
Background image of page 5

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

View Full DocumentRight Arrow Icon
    Building a Stack Class What data items do we need? An array/linked-list to hold stack elements An integer/pointer to indicate the top of stack What operations do we need? Constructor: build an empty stack Empty: check if a stack is empty Push: add an element on the top Top: return the top element Pop: remove the top element Display: show all the stack elements
Background image of page 6
    A Static Array-Based Stack (p327) A static array to hold the stack elements, the position 0 as  the bottom of the stack Problem?   the stack capacity cannot be changed during  run time (waste of space or insufficient room for more  data items)
Background image of page 7

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

View Full DocumentRight Arrow Icon
    Dynamic Array-Based Stack Advantage:  allow users to specify the stack capacity in its  declaration But, we need to do more ! (Due to the dynamically- allocated memory) Constructor: memory allocation and data member initialization
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 31

lecture3-1 - ReviewofStacksandQueues Dr.YingwuZhu OurFocus

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

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