Packagede.polygonal.ds
Classpublic class DLinkedList
InheritanceDLinkedList Inheritance Object
Implements Collection

A doubly linked list.



Public Properties
 PropertyDefined By
  head : DListNode
The head node being referenced.
DLinkedList
  size : int
[read-only] The total number of items.
DLinkedList
  tail : DListNode
The tail node being referenced.
DLinkedList
Public Methods
 MethodDefined By
  
DLinkedList(... args)
Initializes an empty list.
DLinkedList
  
append(... args):DListNode
Appends items to the list.
DLinkedList
  
clear():void
Clears all items.
DLinkedList
  
Concatenates the current list with all lists specified in the parameters and returns a new linked list.
DLinkedList
  
contains(obj:*):Boolean
Determines if the collection contains a given item.
DLinkedList
  
dump():String
Prints out all elements (for debug/demo purposes).
DLinkedList
  
Initializes an iterator object pointing to the first item in the collection.
DLinkedList
  
Creates a list iterator object pointing to the first node in the list.
DLinkedList
  
Inserts an item after a given iterator or appends it if the iterator is invalid.
DLinkedList
  
Inserts an item before a given iterator or appends it if the iterator is invalid.
DLinkedList
  
isEmpty():Boolean
Checks if the collection is empty.
DLinkedList
  
join(sep:*):String
Converts the data in the linked list to strings, inserts the given separator between the elements, concatenates them, and returns the resulting string.
DLinkedList
  
Searches for an item in the list, working backward from the last item, by using strict equality (===) and returns an iterator pointing to the node containing the item or null if the item was not found.
DLinkedList
  
merge(... args):void
Merges the current list with all lists specified in the paramaters.
DLinkedList
  
nodeOf(obj:*, from:DListIterator = null):DListIterator
Searches for an item in the list by using strict equality (===) and returns an iterator pointing to the node containing the item or null if the item was not found.
DLinkedList
  
popDown():void
Removes and prepends the tail node to the head.
DLinkedList
  
prepend(... args):DListNode
Prepends items to the list.
DLinkedList
  
remove(itr:DListIterator):Boolean
Removes the node the iterator is pointing to while moving the iterator to the next node.
DLinkedList
  
Removes the head of the list and returns the head's data or null if the list is empty.
DLinkedList
  
Removes the tail of the list and returns the tail's data or null if the list is empty.
DLinkedList
  
reverse():void
Reverses the linked list in place.
DLinkedList
  
shiftUp():void
Removes and appends the head node to the tail.
DLinkedList
  
sort(... sortOptions):void
Sorts the list.
DLinkedList
  
splice(start:DListIterator, deleteCount:uint = 0xffffffff, ... args):DLinkedList
Adds nodes to and removes nodes from the list.
DLinkedList
  
toArray():Array
Converts the collection into an array.
DLinkedList
  
toString():String
Prints out a string representing the current object.
DLinkedList
Property Detail
headproperty
public var head:DListNode

The head node being referenced. This is the first node in the list.

sizeproperty 
size:int  [read-only]

The total number of items.


Implementation
    public function get size():int
tailproperty 
public var tail:DListNode

The tail node being referenced. This is the last node in the list.

Constructor Detail
DLinkedList()Constructor
public function DLinkedList(... args)

Initializes an empty list. You can add initial items by passing them as a comma-separated list of values.

Parameters
... args — A list of comma-separated values to append.
Method Detail
append()method
public function append(... args):DListNode

Appends items to the list.

Parameters

... args — A list of comma-separated values to append.

Returns
DListNode — A DListNode object wrapping the data. If multiple values are added, the returned node represents the node that stores the data of the first argument.
clear()method 
public function clear():void

Clears all items.

concat()method 
public function concat(... args):DLinkedList

Concatenates the current list with all lists specified in the parameters and returns a new linked list. The original list and all passed lists are left unchanged.

Parameters

... args — A list of one or more comma-separated DLinkedList objects.

Returns
DLinkedList — A copy of the current list which also stores the values from the passed lists.

See also

contains()method 
public function contains(obj:*):Boolean

Determines if the collection contains a given item.

Parameters

obj:* — The item to search for.

Returns
Boolean — True if the item exists, otherwise false.
dump()method 
public function dump():String

Prints out all elements (for debug/demo purposes).

Returns
String — A human-readable representation of the structure.
getIterator()method 
public function getIterator():Iterator

Initializes an iterator object pointing to the first item in the collection.

Returns
Iterator — An iterator object.
getListIterator()method 
public function getListIterator():DListIterator

Creates a list iterator object pointing to the first node in the list.

Returns
DListIterator
insertAfter()method 
public function insertAfter(itr:DListIterator, obj:*):DListNode

Inserts an item after a given iterator or appends it if the iterator is invalid.

Parameters

itr:DListIterator — An iterator object pointing to the node after which the given data is inserted.
 
obj:* — The data to insert.

Returns
DListNode — A doubly linked list node wrapping the data.
insertBefore()method 
public function insertBefore(itr:DListIterator, obj:*):DListNode

Inserts an item before a given iterator or appends it if the iterator is invalid.

Parameters

itr:DListIterator — An iterator object pointing to the node before which the given data is inserted.
 
obj:* — The data to insert.

Returns
DListNode — A doubly linked list node wrapping the data.
isEmpty()method 
public function isEmpty():Boolean

Checks if the collection is empty.

Returns
Boolean — True if empty, otherwise false.
join()method 
public function join(sep:*):String

Converts the data in the linked list to strings, inserts the given separator between the elements, concatenates them, and returns the resulting string.

Parameters

sep:*

Returns
String — A string consisting of the data converted to strings and separated by the specified parameter.
lastNodeOf()method 
public function lastNodeOf(obj:*, from:DListIterator = null):DListIterator

Searches for an item in the list, working backward from the last item, by using strict equality (===) and returns an iterator pointing to the node containing the item or null if the item was not found.

Parameters

obj:* — The item to search for.
 
from:DListIterator (default = null) — A DListIterator object pointing to the node in the list from which to start searching for the item.

Returns
DListIterator — A DListIterator object pointing to the node with the found item or null if no item exists matching the input data or the iterator is invalid.
merge()method 
public function merge(... args):void

Merges the current list with all lists specified in the paramaters. The list is directly modified to reflect the changes. Due to the rearrangement of the node pointers all passed lists become invalid and should be discarded.

Parameters

... args — A list of one or more comma-separated DLinkedList objects.

See also

nodeOf()method 
public function nodeOf(obj:*, from:DListIterator = null):DListIterator

Searches for an item in the list by using strict equality (===) and returns an iterator pointing to the node containing the item or null if the item was not found.

Parameters

obj:* — The item to search for.
 
from:DListIterator (default = null) — A DListIterator object pointing to the node in the list from which to start searching for the item.

Returns
DListIterator — An DListIterator object pointing to the node with the found item or null if no item exists matching the input data or the iterator is invalid.
popDown()method 
public function popDown():void

Removes and prepends the tail node to the head.

prepend()method 
public function prepend(... args):DListNode

Prepends items to the list.

Parameters

... args — A list of comma-separated values to prepend.

Returns
DListNode — A DListNode object wrapping the data. If multiple values are added, the returned node represents the node that stores the data of the first argument.
remove()method 
public function remove(itr:DListIterator):Boolean

Removes the node the iterator is pointing to while moving the iterator to the next node.

Parameters

itr:DListIterator — An iterator object pointing to the node to remove.

Returns
Boolean — True if the removal succeeded, otherwise false.
removeHead()method 
public function removeHead():*

Removes the head of the list and returns the head's data or null if the list is empty.

Returns
* — The data which was associated with the removed node.
removeTail()method 
public function removeTail():*

Removes the tail of the list and returns the tail's data or null if the list is empty.

Returns
* — The data which was associated with the removed node.
reverse()method 
public function reverse():void

Reverses the linked list in place.

shiftUp()method 
public function shiftUp():void

Removes and appends the head node to the tail.

sort()method 
public function sort(... sortOptions):void

Sorts the list. The default sorting algorithm is 'mergesort'. If the LinkedList.INSERTION_SORT flag is used, the list is sorted using the insertion sort algorithm instead, which is much faster for nearly sorted lists.

Parameters

... sortOptions

See also

splice()method 
public function splice(start:DListIterator, deleteCount:uint = 0xffffffff, ... args):DLinkedList

Adds nodes to and removes nodes from the list. This method directly modifies the list without making a copy.

Parameters

start:DListIterator — A DListIterator object pointing to the node where the insertion or deletion begins. The iterator is updated so it still points to the original node, even if the node now belongs to another list.
 
deleteCount:uint (default = 0xffffffff) — An integer that specifies the number of nodes to delete. This number includes the node referenced by the iterator. If no value is specified for the deleteCount parameter, the method deletes all of the nodes from the start iterator to the tail of the list. If the value is 0, no nodes are deleted.
 
... args — Specifies the values to insert into the list, starting at the iterator's node.

Returns
DLinkedList
toArray()method 
public function toArray():Array

Converts the collection into an array.

Returns
Array — An array.
toString()method 
public function toString():String

Prints out a string representing the current object.

Returns
String — A string representing the current object.