Objectives: Discuss linked lists Review Typical operations - - PowerPoint PPT Presentation

objectives
SMART_READER_LITE
LIVE PREVIEW

Objectives: Discuss linked lists Review Typical operations - - PowerPoint PPT Presentation

Linked List Objectives: Discuss linked lists Review Typical operations Linked List Classification: Holds the series of objects (also called node) Singly linked list: each object, except the last one, has an address


slide-1
SLIDE 1

Linked List

  • Objectives:

– Discuss linked lists

  • Review
  • Typical operations
slide-2
SLIDE 2

Linked List

Classification:

  • Holds the series of objects (also called node)
  • Singly linked list: each object, except the last one, has an

address (reference) of another object.

  • 2-way linked list: each object has an address of another
  • bject and in return the referenced object will has the

referencing-object address.

  • Doubly linked list: each object contains 2 addresses to

reference two nodes. One of these two nodes must be of the same type and the other does not.

slide-3
SLIDE 3

Linked List

  • each Node must have at least 2 fields

– Info field

  • Contains information,
  • is an object ( not a node object) from another well-defined

class

– Link field

  • Contains a reference to another Node
  • Is the address of a Node
  • The address can be its own Node address.
  • It can be null. That mean it has no Node to reference to.
slide-4
SLIDE 4

Linked List

  • Example of a Node at 2205 in heap

7 EE01 infoField(int) address 2205

slide-5
SLIDE 5

Memory (RAM) structure

One Byte

8-bit data bus

Address Bus

slide-6
SLIDE 6

Simple Node and RAM

0000 0000

8-bit data bus

Hex: 2205 Bin: 0010 0010 0000 0101

0000 1001 1110 1110 0000 0001

slide-7
SLIDE 7

Symbolic Node

One Node Reference line

slide-8
SLIDE 8

Symbolic Internal Node

infoField Reference line

slide-9
SLIDE 9

Reference Variable & Node

Variable name: head Ref head infoField

slide-10
SLIDE 10

Singly linked list

  • 2 nodes

head

null

slide-11
SLIDE 11

circular linked list

  • 3 nodes

head

slide-12
SLIDE 12

2-way linked list

  • 3 nodes

head

null null

tail

slide-13
SLIDE 13

Doubly linked list

  • 3 nodes

head

null null null null

slide-14
SLIDE 14

Insert a new node

  • The dotted linked must be established.
  • head = new Node(new (infoField) , head ) ;

head

null

slide-15
SLIDE 15

Delete a node

  • The dotted linked must be established.
slide-16
SLIDE 16

Linked List

summary

  • store many objects with one or more references
  • the objects are created by new and inserted into the list.
  • An object is deleted when it is de-linked out of the list. This object

will not be discarded in the memory until Virtual Machine reclaims it.