class List_Extra<X> |
public:
These functions are used for converting Nodes (efficient O(1)
access) to indices (inefficient O(n) access) and vice-versa.
Functions get_index and get_element_at are inverses of each other.
Note that indices start from zero, like C/C++/Java arrays.
Examples of inverse property: Variables n is a Node<X>* and i is an int
get_element_at(n->get_owner(),get_index(n)) == n.
get_index(get_element_at(list,i)) == i
Returns the index of a given node.
friend int get_index(const Node<X>* node)
Returns the node of a given index.
friend Node<X>* get_element_at(List<X>* list, int index)
Returns the const node of a given index.
friend Node<X>* get_element_at_const(const List<X>* list, int index)
These functions internally call get_element_at function.
friend void set_element_at(List<X>* list, int index, X* x)
friend void set_element_at(List<X>* list, int index, Node<X>* node)
|
Find functions. Each function takes O(n) time.
Finds the first node matching element in the sense of operator == (const X*, const X*)
searching forward from start.
friend Node<X>* find_element_eq(Node<X>* start, const X* element)
Const version of the above function.
friend const Node<X>* find_element_eq_const(const Node<X>* start, const X* element)
|
Creates a shallow clone of list. Takes O(n) time.
friend List<X>* clone_shallow(List<X>* list)
|
Deletes duplicates in the sense of operator == (void*, void*). Takes O(n^2) time.
friend void delete_duplicates_eq(List<X>* list)
|
Does a quicksort of the given list.
friend void quicksort(List<X>* list, bool is_le(X* x1, X* x2))
|
Inessential List functions. Each function takes O(1) time.
Abbreviation for: (list->get_length() == 0)
bool is_empty(List<X>* list);
Convenient methods for efficiently accessing second, third, second to last and
third to last elements of list. Assertion fails if no such element exists.
friend Node<X>* get_second(List<X>* list)
friend Node<X>* get_third(List<X>* list)
friend Node<X>* get_second_to_last(List<X>* list)
friend Node<X>* get_third_to_last(List<X>* list)
Const versions of the above functions.
friend const Node<X>* get_second_const(const List<X>* list)
friend const Node<X>* get_third_const(const List<X>* list)
friend const Node<X>* get_second_to_last_const(const List<X>* list)
friend const Node<X>* get_third_to_last_const(const List<X>* list)
|
Inessential Node functions. Each function takes O(1) time.
Abbreviation for (node->get_previous_const() == null)
friend bool is_first(const Node<X>* node)
Abbreviation for (node->get_next_const() == null)
friend bool is_last(const Node<X>* node)
Abbreviation for
((node->get_next() != null) ? node->get_next() : node->get_owner()->get_first())
friend Node<X>* cyclic_next(Node<X>* node);
Abbreviation for
((node->get_previous() != null) ? node->get_previous() : node->get_owner()->get_last())
friend Node<X>* cyclic_previous(Node<X>* node);
Const versions of the above functions.
friend const Node<X>* cyclic_next_const(const Node<X>* node);
friend const Node<X>* cyclic_previous_const(const Node<X>* node);
|