new LinkedList()
js_cols.LinkedList provides the implementation of a doubly Linked List. The list is circular, keeping a dummy element ("sentinel") .
The assymptotic running time for important operations are below:
Method big-O ---------------------------------------------------------------------------- - add O(n/2) - addFirst O(1) - addLast O(1) - clear O(1) - clone O(n) - contains O(n) - containsAll O(n*m) m is the cardinality of the supplied collection - every O(n * O(f)) f is the function supplied as argument - filter O(n * O(f)) f is the function supplied as argument - forEach O(n * O(f)) f is the function supplied as argument - getValues O(n) - insertAll O(m) m is the cardinality of the supplied collection - map O(n * O(f)) f is the function supplied as argument - remove O(n) - removeAll O(n*m) m is the cardinality of the supplied collection - removeFirst O(1) - removeLast O(1) - some O(n * O(f)) f is the function supplied as argument - contains O(n * O(f)) f is the function supplied as argument
Classes
Methods
-
add(index, element)
-
Adds an element at index i in the list
Parameters:
Name Type Description index
Integer the index of the element
element
* the element to add
-
addFirst(element)
-
Adds an element to the beginning of the list
Parameters:
Name Type Description element
* the element to add
-
addLast(element)
-
Adds an element to the end of the list
Parameters:
Name Type Description element
* the element to add
-
clear()
-
Removes all elements from the list.
-
clone() → {js_cols.LinkedList}
-
Creates a new list and inserts all elements from this list to the new list and returns it
Returns:
a shallow clone of this list
- Type
- js_cols.LinkedList
-
contains(o)
-
Checks whether a given element is contained in the list
Parameters:
Name Type Description o
* the element to locate
-
containsAll(col) → {Boolean}
-
Checks that all values contained in the collection are also contained in the LinkedList WARNING: this runs in O(n*m) where n is the cardinality of the LinkedList and m is the cardinality of the collection
Parameters:
Name Type Description col
Returns:
- Type
- Boolean
-
every(f, opt_obj) → {boolean}
-
Calls a function on each item in the LinkedList and returns true only if every function call returns a true-like value.
Parameters:
Name Type Argument Description f
function The function to call for each item. The function takes three arguments: the value, the key, and the LinkedList, and returns a boolean.
opt_obj
Object <optional>
The object context to use as "this" for the function.
Returns:
Whether f evaluates to true for every element in the LinkedList.
- Type
- boolean
-
filter(f, opt_obj) → {Array}
-
Calls a function on each item in the LinkedList, if the function returns true, the key/value pair is inserted into an object that is returned when all elements in the the list has been visited
Parameters:
Name Type Argument Description f
function The function to call for each item. The function takes three arguments: the value, the key, and the LinkedList.
opt_obj
Object <optional>
The object context to use as "this" for the function.
Returns:
The elements that evaluated to true in the function calls for each element in the LinkedList.
- Type
- Array
-
forEach(f, opt_obj)
-
Calls a function on each item in the LinkedList.
Parameters:
Name Type Argument Description f
function The function to call for each item. The function takes three arguments: the value, the key, and the LinkedHashMap.
opt_obj
Object <optional>
The object context to use as "this" for the function.
-
getCount() → {Integer}
-
Returns the number of elements in the list
Returns:
number of elements in the list
- Type
- Integer
-
getFirst() → {*}
-
Returns the first element in the list
Returns:
the first element of the list
- Type
- *
-
getLast() → {*}
-
Returns the last element in the list
Returns:
the last element of the list
- Type
- *
-
getValues() → {Array}
-
Returns the values of the list in an Array. This operation is equal to toArray
Returns:
The values in the list.
- Type
- Array
-
insert(element)
-
Inserts an element to the head of the list this operation is equal to addFirst
Parameters:
Name Type Description element
* the element to insert
-
insertAll(col)
-
Inserts all values from the collection into the list
Parameters:
Name Type Description col
-
isEmpty() → {Boolean}
-
Returns true if the size of the list is zero.
Returns:
- Type
- Boolean
-
iterator(startpos) → {js_cols.LinkedList.LinkedListIterator}
-
Returns an iterator over the list, starting at the specified position
Parameters:
Name Type Description startpos
Integer the start position of this Iterator
Returns:
an iterator over the elements in the list
-
map(f, opt_obj) → {Array}
-
Calls a function on each item in the LinkedList and returns the results of those calls in an array.
Parameters:
Name Type Argument Description f
function The function to call for each item. The function takes three arguments: the value, the key, and the LinkedList.
opt_obj
Object <optional>
The object context to use as "this" for the function.
Returns:
The results of the function calls for each element in the LinkedList.
- Type
- Array
-
remove(o) → {Boolean}
-
This operation is equal to removeObject Removes a given element from the list, if it is contained
Parameters:
Name Type Description o
* the element to remove
Returns:
wheter the object was removed;
- Type
- Boolean
-
removeAll(col)
-
Removes a all values contained in the collection from the list. WARNING: this runs in O(n*m) where n is the cardinality of the LinkedList and m is the cardinality of the collection
Parameters:
Name Type Description col
-
removeFirst() → {*}
-
Removes and returns the first element in the list
Returns:
the first element of the list
- Type
- *
-
removeIndex(index)
-
Removes the element at index i from the list
Parameters:
Name Type Description index
Integer the index of the element to remove
-
removeLast() → {*}
-
Removes and returns the last element in the list
Returns:
the last element of the list
- Type
- *
-
removeObject(o) → {Boolean}
-
Removes a given element from the list, if it is contained
Parameters:
Name Type Description o
* the element to remove
Returns:
wheter the object was removed;
- Type
- Boolean
-
some(f, opt_obj) → {boolean}
-
Calls a function on each item in the LinkedList and returns true if any of those function calls returns a true-like value.
Parameters:
Name Type Argument Description f
function The function to call for each item. The function takes three arguments: the value, the key, and the LinkedList, and returns a boolean.
opt_obj
Object <optional>
The object context to use as "this" for the function.
Returns:
Whether f evaluates to true for at least one element in the LinkedList.
- Type
- boolean
-
toArray() → {Array}
-
Returns an Array with the values of the list.
Returns:
The values in the list.
- Type
- Array