Stacks and Queues - Data Structures | CSCI 3230, Study notes of Data Structures and Algorithms

Material Type: Notes; Professor: Acharya; Class: Data Structures; Subject: CSCI Computer Science; University: Georgia Southern University; Term: Fall 2009;

Typology: Study notes

Pre 2010

Uploaded on 11/02/2009

eagleboy-1
eagleboy-1 🇺🇸

19 documents

1 / 46

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Stacks and Queues
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e

Partial preview of the text

Download Stacks and Queues - Data Structures | CSCI 3230 and more Study notes Data Structures and Algorithms in PDF only on Docsity!

Stacks and Queues

Stacks

Stack

A stack

 Last-in, first-out (LIFO)

property

 The last item placed on
the stack will be the first
item removed

 Analogy

 A stack of dishes in a
cafeteria

Stack of cafeteria dishes

Operations in Stack 

The main primitives of a stack are known as:

 Push  adds a new node
 Pop  removes a node

 Additional primitives can be defined:

 IsEmpty  reports whether the stack is empty
 IsFull  reports whether the stack is full
 Initialize  creates/initializes the stack
 Destroy  deletes the contents of the stack (may be implemented
by re-initializing the stack)

Operations in Stack

Operations in Stack

Stack Implementation  The Java Collections Framework includes a set of ready made data structure classes, including a Stack class.  However, we will create our own stack class order to learn how a stack is implemented.  Our class will be a bit simpler than the Collections Framework.

Stack Implementation

 A stack can be stored in:

 (^) a static data structure

OR

 (^) a dynamic data structure

 Static data structures

 (^) These define collections of data which are fixed in size when the program is compiled. An array is a static data structure.

 Dynamic data structures

 (^) These define collections of data which are variable in size and structure. They are created as the program executes, and grow and shrink to accommodate the data being stored.

Stack Implementation

Stack Implementation

Stack Implementation

Simple Applications of Stack:

Checking for Balanced Braces

A stack can be used to verify whether a program contains balanced braces

 An example of balanced braces

abc{defg{ijk}{l{mn}}op}qr

 An example of unbalanced braces

abc{def}}{ghij{kl}m

Checking for Balanced Braces Traces of the algorithm that checks for balanced braces

Implementations of Stack

Implementation of the stack that use a) an array; b) a linked list;