MATLAB Object-Oriented Programming

(Joyce) #1

Implementing Linked Lists with Classes


In this section...
“Class Definition Code” on page 3-31
“dlnode Class Design” on page 3-31
“Create Doubly Linked List” on page 3-32
“Why a Handle Class for Linked Lists?” on page 3-34
“dlnode Class Synopsis” on page 3-34
“Specialize the dlnode Class” on page 3-46

Class Definition Code


For the class definition code listing, see “dlnode Class Synopsis” on page 3-34.

To use the class, create a folder named @dlnode and save dlnode.m to this folder. The
parent folder of @dlnode must be on the MATLAB path. Alternatively, save dlnode.m to
a path folder.

dlnode Class Design


dlnode is a class for creating doubly linked lists in which each node contains:


  • Data array

  • Handle to the next node

  • Handle to the previous node


Each node has methods that enable the node to be:


  • Inserted before a specified node in a linked list

  • Inserted after a specific node in a linked list

  • Removed from a list


Class Properties

The dlnode class implements each node as a handle object with three properties:

Implementing Linked Lists with Classes
Free download pdf