class Linkedlist::Singly(T)

Defined in:

linkedlist/singly.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

Intializes a singly linked list


[View source]

Instance Method Detail

def find_element(value : T) : Linkedlist::SinglyNode(T) #

Returns the first element with value or raises exception if not found

Running time: O(n)


[View source]
def find_element(element : Linkedlist::SinglyNode(T)) : Linkedlist::SinglyNode(T) #

Returns the element if found or raises exception

Running time: O(n)


[View source]
def find_element?(value : T) : Linkedlist::SinglyNode(T)? #

Returns the first element with value or nil if not found

Running time: O(n)


[View source]
def find_element?(element : Linkedlist::SinglyNode(T)) : Linkedlist::SinglyNode(T)? #

Returns the element if found or nil if not found

Running time: O(n)


[View source]
def head #

Returns the head of linked list

Running time: O(1)


[View source]
def insert_after(value : T, mark : Linkedlist::SinglyNode(T)) : Linkedlist::SinglyNode(T) #

Inserts new element after the mark or raises exception if mark not found

Running time: O(n)


[View source]
def insert_after(element : Linkedlist::SinglyNode(T), mark : Linkedlist::SinglyNode(T)) #

Inserts given element after the mark or raises exception if mark not found

Running time: O(n)


[View source]
def insert_after?(value : T, mark : Linkedlist::SinglyNode(T)) : Linkedlist::SinglyNode(T)? #

Inserts new element after the mark or returns nil if mark not found

Running time: O(n)


[View source]
def insert_before(value : T, mark : Linkedlist::SinglyNode(T)) : Linkedlist::SinglyNode(T) #

Inserts new element before the mark or raises exception if mark not found

Running time: O(n)


[View source]
def insert_before(element : Linkedlist::SinglyNode(T), mark : Linkedlist::SinglyNode(T)) #

Inserts given element before the mark or returns nil if mark not found

Running time: O(n)


[View source]
def insert_before?(value : T, mark : Linkedlist::SinglyNode(T)) : Linkedlist::SinglyNode(T)? #

Inserts new element before the mark or returns nil if mark not found

Running time: O(n)


[View source]
def insert_head(data : T) #

Inserts new element at the head of the linked list

Running time: O(1)


[View source]
def insert_tail(data : T) #

Inserts new element at the tail of the linked list

Running time: O(1)


[View source]
def length #

Returns the length of linked list.

Running time: O(1)


[View source]
def move_after(element : Linkedlist::SinglyNode(T), mark : Linkedlist::SinglyNode(T)) #

Moves element after the mark, if element and mark are present and not equal

Running time: O(n)


[View source]
def move_before(element : Linkedlist::SinglyNode(T), mark : Linkedlist::SinglyNode(T)) #

Moves element before the mark, if element and mark are present and not equal

Running time: O(n)


[View source]
def move_to_back(element : Linkedlist::SinglyNode(T)) #

Moves element to front if found. List is unmodified otherwise.

Running time: O(n)


[View source]
def move_to_front(element : Linkedlist::SinglyNode(T)) #

Moves element to front if found. List is unmodified otherwise.

Running time: O(n)


[View source]
def previous_element?(element : Linkedlist::SinglyNode(T)) : Linkedlist::SinglyNode(T)? #

Returns the previous element if element found or nil if not found

Running time: O(n)


[View source]
def remove(element : Linkedlist::SinglyNode(T)) : T #

Removes an element from the linked list and returns the data

Running time: O(n)


[View source]
def remove?(element : Linkedlist::SinglyNode(T)) : Linkedlist::SinglyNode(T)? #

Removes an element from the linked list and returns the element

Running time: O(n)


[View source]
def tail #

Returns the tail of linked list

Running time: O(1)


[View source]