MATLAB Object-Oriented Programming

(Joyce) #1

  • Data — Contains the data for this node

  • Next — Contains the handle of the next node in the list (SetAccess = private)

  • Prev — Contains the handle of the previous node in the list (SetAccess = private)


This diagram shows a list with three-nodes n1, n2, and n3. It also shows how the nodes
reference the next and previous nodes.

n3

Properties
Next
Prev

n2

Properties
Next
Prev

n1

Properties
Next
Prev

n2.Prev n2 n2.Next

Class Methods

The dlnode class implements the following methods:


  • dlnode — Construct a node and assign the value passed as an input to the Data
    property

  • insertAfter — Insert this node after the specified node

  • insertBefore — Insert this node before the specified node

  • removeNode — Remove this node from the list and reconnect the remaining nodes

  • clearList — Remove large lists efficiently

  • delete — Private method called by MATLAB when deleting the list.


Create Doubly Linked List


Create a node by passing the node's data to the dlnode class constructor. For example,
these statements create three nodes with data values 1 , 2 , and 3 :

n1 = dlnode(1);
n2 = dlnode(2);
n3 = dlnode(3);

Build these nodes into a doubly linked list using the class methods designed for this
purpose:

3 MATLAB Classes Overview

Free download pdf