A linked list is a container style data structure that provides efficient support for the addition, removal and sequential traversal of objects. More...
Extended by: | |
Constructors: | |
Methods: |
|
A linked list works by connecting elements together with 'next' and 'previous' references, making it very efficient to get from one element to the next, but not so efficient for accessing arbitrary elements.
This connection between elements is achieved using separate Node objects (there is one per element) which contain references to the next and previous nodes in the list, as well as the actual object managed by the node.
Returns an object that may be used to iterate backwards through the list with a For EachIn loop.
Note that this doesn't not actually reverse or modify the list in any way.
Function
Main
()
Local
list
:=
New
StringList
list.AddLast
"Hello"
list.AddLast
"there"
list.AddLast
"this"
list.AddLast
"is"
list.AddLast
"a"
list.AddLast
"test"
Print
"Fowards:"
For
Local
t
$=
EachIn
list
Print
t
Next
Print
""
Print
"Backwards:"
For
Local
t
$=
Eachin
list.Backwards
()
Print
t
Next
End
Returns the number of elements in the list.
Note that this method takes time proportional to the number of elements in the list.
This method is used by the Contains, RemoveFirst, RemoveLast and RemoveEach methods to determine element equality.
By default, this method compares lhs and rhs using the '=' operator. Extending classes may override this method to provide their own equality test.
Finds the node containing the first element in the list equal to value.
If no matching node is found, Null is returned.
Finds the node containing the last element in the list equal to value.
If no matching node is found, Null is returned.
Returns the first element in the list.
Using this method on an empty list will cause a runtime error in debug mode, and undefined behavior in release mode.
Inserts data after the first element in the list equal to where.
Inserts data after each element in the list equal to where.
Inserts data before the first element in the list equal to where.
Inserts data before each element in the list equal to where.
Returns the last element in the list.
Using this method on an empty list will cause a runtime error in debug mode, and undefined behavior in release mode.
Finds and removes each element in the list equal to value.
See also Equals
Removes the first value in the list and returns it.
Using this method on an empty list will cause a runtime error in debug mode, and undefined behavior in release mode.
Finds and removes the first element in the list equal to value.
See also Equals
Removes the last value in the list and returns it.
Using this method on an empty list will cause a runtime error in debug mode, and undefined behavior in release mode.
Finds and removes the last element in the list equal to value.
See also Equals