Unformatted text preview:

What is a stack Stacks Last in first out data structure LIFO New objects are placed on top Removal restricted to top object Examples Stack ADT Operations push o Insert o at top of stack Input Object Output None pop Remove top object error if empty Input None Output Object removed size Return number of objects in stack Input None Output Integer isEmpty Return a boolean indicating stack empty Input None Output Boolean top Return top object without removing error if empty Input None Output Object Example push 5 push 3 pop push 7 pop top pop pop isEmpty Implementing a Stack Implementation involves writing one or more classes which provide functions to accomplish stack operations push 9 push 7 push 3 push 5 size pop push 8 pop pop Stack Interface int size boolean isEmpty Object top throws StackEmptyException void push Object obj Object pop throws StackEmptyException 1 Underlying Representation Array versus Linked List Pros and cons Running time size isEmpty push pop top 2


View Full Document

USF CS 112 - Stacks

Documents in this Course
Structs

Structs

4 pages

Trees

Trees

25 pages

Strings

Strings

27 pages

Queues

Queues

3 pages

Trees

Trees

24 pages

Arrays

Arrays

5 pages

ArrayList

ArrayList

24 pages

Stacks

Stacks

8 pages

Trees

Trees

24 pages

Stacks

Stacks

8 pages

Queues

Queues

16 pages

Queues

Queues

17 pages

Queues

Queues

17 pages

Load more
Loading Unlocking...
Login

Join to view Stacks and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Stacks and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?