For Tuesday Read Weiss, chapter 4, sections 1,2,6 This should again - - PowerPoint PPT Presentation

for tuesday
SMART_READER_LITE
LIVE PREVIEW

For Tuesday Read Weiss, chapter 4, sections 1,2,6 This should again - - PowerPoint PPT Presentation

For Tuesday Read Weiss, chapter 4, sections 1,2,6 This should again be review as far as concepts. Can refer to Savitch for more on C++ Homework: List practice homework described on ReggieNet Late Passes You have 2 for the


slide-1
SLIDE 1

For Tuesday

  • Read Weiss, chapter 4, sections 1,2,6

– This should again be review as far as concepts. – Can refer to Savitch for more on C++

  • Homework:

– List practice homework described on ReggieNet

slide-2
SLIDE 2

Late Passes

  • You have 2 for the semester.
  • Only good for programs and papers.
  • Allow you to hand in up to 5 days late IF

you have a late pass left.

  • Each good for +.05 on final grade if unused.
  • Must acknowledge the use of the late pass.
  • Only way to turn in late work in this course.
slide-3
SLIDE 3

Programming Assignment 1

slide-4
SLIDE 4

Linked Lists

  • What’s the basic concept?
slide-5
SLIDE 5

What Is a Node?

  • Two parts

– Data – Pointer to the next one

  • Make the data public
  • Do provide a constructor with appropriate

defaults

slide-6
SLIDE 6

Creating Nodes

  • We’ll always create nodes dynamically.
  • Note that we almost never actually work

with a node itself; we use pointers to the nodes.

  • Important:

– ALWAYS initialize next to NULL when a node is created unless you are immediately assigning it another meaningful value.

slide-7
SLIDE 7

C++ Details

  • Deleting nodes . . .
slide-8
SLIDE 8

Linked List Variations

  • Doubly-linked lists
  • Empty head node
slide-9
SLIDE 9

Stacks

  • What is a stack?
  • What would a stack ADT look like?
  • How could you implement a stack?
  • What are stacks used for?
slide-10
SLIDE 10

Stack ADT

  • AbstractDataType Stack {

instances linear list of elements; one end is the top

  • perations

IsEmpty() IsFull() (not always needed) Top() Push(element) Pop() }

slide-11
SLIDE 11

Queues

  • What is a queue?
  • What would a queue ADT look like?
  • How could you implement a queue?
  • What are queues used for?
slide-12
SLIDE 12

Queue ADT

  • AbstractDataType Queue {

instances linear list of elements; one end is the front, the other the rear

  • perations

IsEmpty() IsFull() (not always needed) Front() Add(elem) (or Put(elem) or Enqueue(elem)) Delete() (or Get() or Dequeue()) }

slide-13
SLIDE 13

A Note on Push and Pop

  • In this class, do not use push and pop to

refer to queue operations.

  • They should only apply to stack operations.
slide-14
SLIDE 14

Queues and Stacks

  • Often used in similar contexts to achieve

different desired results.

  • Often used in conjunction with other data

structures.

slide-15
SLIDE 15

Trees

  • Hierarchical structure
  • Single root
  • Each node has zero or more children
  • Each node except the root has exactly one

parent

slide-16
SLIDE 16

Tree Definition

  • A tree t is a finite nonempty set of elements.

One of these elements is called the root, and the remaining elements (if any) are partitioned into trees which are called the subtrees of t.

slide-17
SLIDE 17

Tree Vocabulary

  • Root
  • Child
  • Parent
  • Sibling
  • Grandchild
  • Grandparent
  • Ancestor
  • Descendent
  • Leaf
  • Subtree
  • Forest
  • Degree
  • Level
  • Height
slide-18
SLIDE 18

Tree properties

  • There is exactly one path connecting any

two nodes in a tree.

– Least common ancestor – Any node could be a root.

  • A tree with N nodes has N-1 edges.