Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * ~~~ Pointer magic ~~~
- * The address of the next pointer of the previous element
- * In case of index == 0: Address of the head
- * @param index the index
- * @return the address of the next pointer of the previous element
- */
- std::shared_ptr<ListNode<T>> *prevElementNextPointer(unsigned int index) const {
- auto *to_return = const_cast<std::shared_ptr<ListNode<T>> *>(&head);
- if (2 * index <= length + 3) {
- for (unsigned int i = 0; i < index; i++)
- to_return = &((*to_return)->next);
- } else {
- ListNode<T> *curr_pointer = (*to_return).get();
- for (unsigned int i = length + 1; i >= index; i--)
- curr_pointer = (curr_pointer->prev).lock().get();
- to_return = &curr_pointer->next;
- }
- return to_return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement