1 Info 3.2. Chapter 3.2 Recursive Data Structures Part 1 : Linear Lists.
Linear Recursive Structures(LRS)
-
Upload
jacqueline-simon -
Category
Documents
-
view
39 -
download
0
description
Transcript of Linear Recursive Structures(LRS)
04/19/23 B.Ramamurthy 1
Linear Recursive Structures(LRS)
Based on paper by D.Nyguen
04/19/23 B.Ramamurthy 2
Recursive Definition
List is an Empty listOr a NonEmptyList with a head Object and a tail which is a List.Empty list is typically represented by “null” giving rise to the famous NullPointerException. In this paper, EmptyList is represented by a NullObject (Pattern).
04/19/23 B.Ramamurthy 3
NonEmptyList
List:
tail
Object
head
List
tail
Object
head
tail
Object
head
List (can be empty)
List:
tail
Object
head
tail
Object
headList:
tail
Object
head
List
04/19/23 B.Ramamurthy 4
State-pattern based approach
EmptyNonEmpty
Add an Object
Remove an Objectsingleton Represents all
Possible nonEmptystates
Add an ObjectRemoveAn object
04/19/23 B.Ramamurthy 5
List operations (add, remove)
List operations depend on the state of the list.Define a class hierarchy for state and polymorphically delegate the operations to the different types of states.Using State pattern: an abstract class specifies operations that are state dependent. A concrete class is defined for each discrete/functionally distinguishable state.
UML Class Diagram
IContainer<<interface>>
AListNode<<Abstract class>>
EmptyListNode<<state>>
NonEmptyListNode
Object head;List tail;
<<state>>
List<<Concrete class>>
knows aknows a