<<

Scientific Computing (PHYS 2109/Ast 3100 H) I. Scientific Software Development

SciNet HPC Consortium University of Toronto

Winter 2014/2015 Lecture 8:

I Basic Types

I structures

I , Stacks/Queues

I binary Trees

I Hash tables (maps) Basic Types in ++

“Primitive” types * boolean: bool * integer type: [unsigned] short, int, long, long long * floating point type: float, double, long double, std::complex, ... * or string of characters: char, char*, std::string

“Composite” types / “Abstract” Data Structures * array, pointer * class, , enumerated type, union Structures

Classes/Objects Recall Erik’s StoneWt example:

Starting Point...

Pointers Classes/Objects Recall Erik’s StoneWt example:

Starting Point... Structures

Pointers Starting Point... Structures

Pointers

Classes/Objects Recall Erik’s StoneWt example: pmovie->title ≡ (*pmovie).title 6= *pmovie.title ∼ *(pmovie.title) ≡ (*pmovie).title 6= *pmovie.title ∼ *(pmovie.title)

pmovie->title 6= *pmovie.title ∼ *(pmovie.title)

pmovie->title ≡ (*pmovie).title pmovie->title ≡ (*pmovie).title 6= *pmovie.title ∼ *(pmovie.title) Structure w/pointer:

Pointer to a structure: Ptr to a structure w/ptr:

List

Structures: Structure w/pointer:

Ptr to a structure w/ptr:

List

Structures:

Pointer to a structure: Ptr to a structure w/ptr:

List

Structure w/pointer: Structures:

Pointer to a structure: List

Structure w/pointer: Structures:

Pointer to a structure: Ptr to a structure w/ptr: Structure w/pointer: Structures:

Pointer to a structure: Ptr to a structure w/ptr:

List H Queue H Stack

I lifo I fifo H Other examples: double linked lists, circular lists, double-ended queues, ...

Linear Data Structures Lists / Stacks / Queues

H Linked Lists H Queue

I fifo H Other examples: double linked lists, circular lists, double-ended queues, ...

Linear Data Structures Lists / Stacks / Queues

H Linked Lists H Stack

I lifo H Other examples: double linked lists, circular lists, double-ended queues, ...

Linear Data Structures Lists / Stacks / Queues H Queue H Linked Lists H Stack

I lifo I fifo Linear Data Structures Lists / Stacks / Queues H Queue H Linked Lists H Stack

I lifo I fifo H Other examples: double linked lists, circular lists, double-ended queues, ... stack – implementation, from scratch stack – implementation, from scratch stack – implementation, from scratch stack/queue – implementation, using the C++ STL The C++ Standard Library generic collection of class templates and algorithms

H Container class templates: I std::deque, double-ended queue

I std::forward list, singly linked list

I std::list, I std::stack myStack; I std::map/, sorted and multimap I Functions (stack: top, push, pop, size) I std::queue, single-ended queue (std::) I Alogrithms

I std::stack, stack I Modifiers

I std::unordered map/multimap, unordered map/multimap, hash tables

I std::vector, resizable array Binary Trees ± abstract , such each has at most two “children”

« linked abstract data structure composed of nodes « each node contains a field and one or more pointers to other nodes « recursive structures « a linear list is trivially a « graph theory (map)

± abstract data structure used to implement an associative array

« map keys to values « uses a to compute an index into an array of buckets or slots, from which the correct value can be found « aka dictionary or map Data Structures & Algorithms